2 // SoapAttributeOverrides.cs:
\r
5 // John Donagher (john@webmeta.com)
\r
7 // (C) 2002 John Donagher
\r
11 // Permission is hereby granted, free of charge, to any person obtaining
\r
12 // a copy of this software and associated documentation files (the
\r
13 // "Software"), to deal in the Software without restriction, including
\r
14 // without limitation the rights to use, copy, modify, merge, publish,
\r
15 // distribute, sublicense, and/or sell copies of the Software, and to
\r
16 // permit persons to whom the Software is furnished to do so, subject to
\r
17 // the following conditions:
\r
19 // The above copyright notice and this permission notice shall be
\r
20 // included in all copies or substantial portions of the Software.
\r
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using System.Collections;
\r
34 namespace System.Xml.Serialization
\r
39 public class SoapAttributeOverrides
\r
42 /// This class requires to store SoapAttrributes indexed by a key containg
\r
43 /// both Type and Member Name. There are 3 approaches to this IMO.
\r
44 /// 1. Make the key as "FullTypeName..MemberName", with ".." seperating Type and Member.
\r
45 /// 2. Use a jagged 2D hashtable. The main hashtable is indexed by Type and each value
\r
46 /// contains another hashtable which is indexed by member names. (Too many hashtables)
\r
47 /// 3. Use a new class which emcompasses the Type and MemberName. An implementation is there
\r
48 /// in TypeMember class in this namespace. (Too many instantiations of the class needed)
\r
50 /// Method 1 is the most elegent, but I am not sure if the seperator is language insensitive.
\r
51 /// What if someone writes a language which allows . in the member names.
\r
54 private Hashtable overrides;
\r
56 public SoapAttributeOverrides ()
\r
58 overrides = new Hashtable();
\r
61 public SoapAttributes this [Type type]
\r
63 get { return this [type, string.Empty]; }
\r
66 public SoapAttributes this [Type type, string member]
\r
70 return (SoapAttributes) overrides[GetKey(type,member)];
\r
74 public void Add (Type type, SoapAttributes attributes)
\r
76 Add(type, string.Empty, attributes);
\r
79 public void Add (Type type, string member, SoapAttributes attributes)
\r
81 if(overrides[GetKey(type, member)] != null)
\r
82 throw new Exception("The attributes for the given type and Member already exist in the collection");
\r
84 overrides.Add(GetKey(type,member), attributes);
\r
87 private TypeMember GetKey(Type type, string member)
\r
89 return new TypeMember(type, member);
\r
92 internal void AddKeyHash (System.Text.StringBuilder sb)
\r
95 foreach (DictionaryEntry entry in overrides)
\r
97 SoapAttributes val = (SoapAttributes) overrides [entry.Key];
\r
98 sb.Append (entry.Key.ToString()).Append(' ');
\r
99 val.AddKeyHash (sb);
\r