* SerializationCodeGenerator.cs: Added support for generation of readers
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlAttributeOverrides.cs
1 //
2 // XmlAttributeOverrides.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         /// Summary description for XmlAttributeOverrides.\r
17         /// </summary>\r
18         public class XmlAttributeOverrides\r
19         {\r
20                 \r
21                 private Hashtable overrides;\r
22 \r
23                 public XmlAttributeOverrides ()\r
24                 {\r
25                         overrides = new Hashtable();\r
26                 }\r
27 \r
28                 public XmlAttributes this [Type type] \r
29                 {\r
30                         get { return this [type, string.Empty]; }\r
31                 }\r
32 \r
33                 public XmlAttributes this [Type type, string member]\r
34                 {\r
35                         get \r
36                         {\r
37                                 return (XmlAttributes) overrides[GetKey(type,member)];\r
38                         }\r
39                 }\r
40 \r
41                 public void Add (Type type, XmlAttributes attributes) \r
42                 {\r
43                         Add(type, string.Empty, attributes);\r
44                 }\r
45 \r
46                 public void Add (Type type, string member, XmlAttributes attributes) \r
47                 {\r
48                         if(overrides[GetKey(type, member)] != null)\r
49                                 throw new Exception("The attributes for the given type and Member already exist in the collection");\r
50                         \r
51                         overrides.Add(GetKey(type,member), attributes);\r
52                 }\r
53 \r
54                 private TypeMember GetKey(Type type, string member)\r
55                 {\r
56                         return new TypeMember(type, member);\r
57                 }\r
58 \r
59                 internal bool InternalEquals (XmlAttributeOverrides other)\r
60                 {\r
61                         if (other == null) return false;\r
62                         if (overrides.Count != other.overrides.Count) return false;\r
63                         \r
64                         foreach (DictionaryEntry entry in overrides)\r
65                         {\r
66                                 XmlAttributes val = (XmlAttributes) other.overrides [entry.Key];\r
67                                 if (val == null || !val.Equals ((XmlAttributes) entry.Value)) return false;\r
68                         }\r
69                         return true;\r
70                 }\r
71         }\r
72 }