2002-09-19 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / SoapAttributeOverrides.cs
1 //
2 // SoapAttributeOverrides.cs: 
3 //
4 // Author:
5 //   John Donagher (john@webmeta.com)
6 //
7 // (C) 2002 John Donagher
8 //
9
10 using System;\r
11 using System.Collections;\r
12 \r
13 namespace System.Xml.Serialization\r
14 {\r
15         /// <summary>\r
16         /// \r
17         /// </summary>\r
18         public class SoapAttributeOverrides\r
19         {\r
20                 /// <summary>\r
21                 /// This class requires to store SoapAttrributes indexed by a key containg\r
22                 /// both Type and Member Name. There are 3 approaches to this IMO.\r
23                 /// 1. Make the key as "FullTypeName..MemberName", with ".." seperating Type and Member.\r
24                 /// 2. Use a jagged 2D hashtable. The main hashtable is indexed by Type and each value \r
25                 ///    contains another hashtable which is indexed by member names. (Too many hashtables)\r
26                 /// 3. Use a new class which emcompasses the Type and MemberName. An implementation is there\r
27                 ///    in TypeMember class in this namespace. (Too many instantiations of the class needed)\r
28                 ///    \r
29                 /// Method 1 is the most elegent, but I am not sure if the seperator is language insensitive.\r
30                 /// What if someone writes a language which allows . in the member names.\r
31                 /// </summary>\r
32                 /// \r
33                 private Hashtable overrides;\r
34 \r
35                 public SoapAttributeOverrides ()\r
36                 {\r
37                         overrides = new Hashtable();\r
38                 }\r
39 \r
40                 public SoapAttributes this [Type type] \r
41                 {\r
42                         get { return this [type, string.Empty]; }\r
43                 }\r
44 \r
45                 public SoapAttributes this [Type type, string member]\r
46                 {\r
47                         get \r
48                         {\r
49                                 return (SoapAttributes) overrides[GetKey(type,member)];\r
50                         }\r
51                 }\r
52 \r
53                 public void Add (Type type, SoapAttributes attributes) \r
54                 {\r
55                         Add(type, string.Empty, attributes);\r
56                 }\r
57 \r
58                 public void Add (Type type, string member, SoapAttributes attributes) \r
59                 {\r
60                         if(overrides[GetKey(type, member)] != null)\r
61                                 throw new Exception("The attributes for the given type and Member already exist in the collection");\r
62                         \r
63                         overrides.Add(GetKey(type,member), attributes);\r
64                 }\r
65 \r
66                 private TypeMember GetKey(Type type, string member)\r
67                 {\r
68                         return new TypeMember(type, member);\r
69                 }\r
70 \r
71         }\r
72 }\r