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