2009-08-20 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System / System.Collections.Specialized / StringDictionary.cs
1 //\r
2 // System.Collections.Specialized.StringDictionary.cs\r
3 //\r
4 // Author:\r
5 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)\r
6 //\r
7 // (C) Ximian, Inc.  http://www.ximian.com\r
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
9 //\r
10 // Permission is hereby granted, free of charge, to any person obtaining\r
11 // a copy of this software and associated documentation files (the\r
12 // "Software"), to deal in the Software without restriction, including\r
13 // without limitation the rights to use, copy, modify, merge, publish,\r
14 // distribute, sublicense, and/or sell copies of the Software, and to\r
15 // permit persons to whom the Software is furnished to do so, subject to\r
16 // the following conditions:\r
17 // \r
18 // The above copyright notice and this permission notice shall be\r
19 // included in all copies or substantial portions of the Software.\r
20 // \r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
28 //\r
29 \r
30 #if !NET_2_1\r
31 using System.ComponentModel.Design.Serialization;\r
32 #endif\r
33 using System.Globalization;\r
34 \r
35 namespace System.Collections.Specialized {\r
36 \r
37 #if NET_2_0\r
38         [Serializable]\r
39 #endif\r
40 #if !NET_2_1\r
41         [DesignerSerializer ("System.Diagnostics.Design.StringDictionaryCodeDomSerializer, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]\r
42 #endif\r
43         public class StringDictionary : IEnumerable\r
44         {\r
45                 private Hashtable contents;\r
46                         \r
47                 public StringDictionary()\r
48                 {\r
49                         contents = new Hashtable();\r
50                 }\r
51                 \r
52                 // Public Instance Properties\r
53                 \r
54                 public virtual int Count\r
55                 {\r
56                         get {\r
57                                 return contents.Count;\r
58                         }\r
59                 }\r
60                 \r
61                 public virtual bool IsSynchronized\r
62                 {\r
63                         get {\r
64                                 return false;\r
65                         }\r
66                 }\r
67                 \r
68                 public virtual string this[string key]\r
69                 {\r
70                         get {\r
71 #if NET_2_0\r
72                         if (key == null)\r
73                                 throw new ArgumentNullException ("key");\r
74 #endif\r
75                         return (string) contents [key.ToLower (CultureInfo.InvariantCulture)];\r
76                         }\r
77                         \r
78                         set {\r
79 #if NET_2_0\r
80                         if (key == null)\r
81                                 throw new ArgumentNullException ("key");\r
82 #endif\r
83                                 contents[key.ToLower(CultureInfo.InvariantCulture)] = value;\r
84                         }\r
85                 }\r
86                 \r
87                 public virtual ICollection Keys\r
88                 {\r
89                         get {\r
90                                 return contents.Keys;\r
91                         }\r
92                 }\r
93                 \r
94                 public virtual ICollection Values\r
95                 {\r
96                         get {\r
97                                 return contents.Values;\r
98                         }\r
99                 }\r
100                 \r
101                 public virtual object SyncRoot\r
102                 {\r
103                         get {\r
104                                 return contents.SyncRoot;\r
105                         }\r
106                 }\r
107                 \r
108                 // Public Instance Methods\r
109                 \r
110                 public virtual void Add(string key, string value)\r
111                 {\r
112 #if NET_2_0\r
113                         if (key == null)\r
114                                 throw new ArgumentNullException ("key");\r
115 #endif\r
116                         contents.Add (key.ToLower (CultureInfo.InvariantCulture), value);\r
117                 }\r
118                 \r
119                 public virtual void Clear()\r
120                 {\r
121                         contents.Clear();\r
122                 }\r
123                 \r
124                 public virtual bool ContainsKey(string key)\r
125                 {\r
126 #if NET_2_0\r
127                         if (key == null)\r
128                                 throw new ArgumentNullException ("key");\r
129 #endif\r
130                         return contents.ContainsKey (key.ToLower (CultureInfo.InvariantCulture));\r
131                 }\r
132                 \r
133                 public virtual bool ContainsValue(string value)\r
134                 {\r
135                         return contents.ContainsValue(value);\r
136                 }\r
137                 \r
138                 public virtual void CopyTo(Array array, int index)\r
139                 {\r
140                         contents.CopyTo(array, index);\r
141                 }\r
142                 \r
143                 public virtual IEnumerator GetEnumerator()\r
144                 {\r
145                         return contents.GetEnumerator();\r
146                 }\r
147                 \r
148                 public virtual void Remove(string key)\r
149                 {\r
150 #if NET_2_0\r
151                         if (key == null)\r
152                                 throw new ArgumentNullException ("key");\r
153 #endif\r
154                         contents.Remove (key.ToLower (CultureInfo.InvariantCulture));\r
155                 }\r
156         }\r
157 }\r