2003-05-29 Nick Drochak <ndrochak@gol.com>
[mono.git] / mcs / class / Mono.Data / ProviderCollection.cs
1 //\r
2 // Mono.Data.ProviderCollection\r
3 //\r
4 // Authors:\r
5 //   Brian Ritchie (brianlritchie@hotmail.com) \r
6 //  \r
7 //\r
8 // Copyright (C) Brian Ritchie, 2002\r
9 // \r
10 //\r
11 namespace Mono.Data \r
12 {\r
13         using System;\r
14         using System.Collections;\r
15         using System.Collections.Specialized;\r
16         \r
17         \r
18         /// <summary>\r
19         ///     <para>\r
20         ///       A collection that stores <see cref='.Provider'/> objects.\r
21         ///    </para>\r
22         /// </summary>\r
23         /// <seealso cref='.ProviderCollection'/>\r
24         [Serializable()]\r
25         public class ProviderCollection : DictionaryBase  \r
26         {\r
27                 \r
28                 /// <summary>\r
29                 ///     <para>\r
30                 ///       Initializes a new instance of <see cref='.ProviderCollection'/>.\r
31                 ///    </para>\r
32                 /// </summary>\r
33                 public ProviderCollection() \r
34                 {\r
35                 }\r
36                 \r
37                 /// <summary>\r
38                 ///     <para>\r
39                 ///       Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.\r
40                 ///    </para>\r
41                 /// </summary>\r
42                 /// <param name='value'>\r
43                 ///       A <see cref='.ProviderCollection'/> from which the contents are copied\r
44                 /// </param>\r
45                 public ProviderCollection(ProviderCollection value) \r
46                 {\r
47                         this.AddRange(value);\r
48                 }\r
49                 \r
50                 /// <summary>\r
51                 ///     <para>\r
52                 ///       Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.\r
53                 ///    </para>\r
54                 /// </summary>\r
55                 /// <param name='value'>\r
56                 ///       A array of <see cref='.Provider'/> objects with which to intialize the collection\r
57                 /// </param>\r
58                 public ProviderCollection(Provider[] value) \r
59                 {\r
60                         this.AddRange(value);\r
61                 }\r
62                 \r
63                 /// <summary>\r
64                 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>\r
65                 /// </summary>\r
66                 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>\r
67                 /// <value>\r
68                 ///    <para> The entry at the specified index of the collection.</para>\r
69                 /// </value>\r
70                 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>\r
71                 public Provider this[string Name] \r
72                 {\r
73                         get \r
74                         {\r
75                                 return ((Provider)(Dictionary[Name]));\r
76                         }\r
77                         set \r
78                         {\r
79                                 Dictionary[Name] = value;\r
80                         }\r
81                 }\r
82 \r
83                 public Provider FindByCommandType(Type CommandType)\r
84                 {\r
85                         foreach (Provider p in this)\r
86                         {\r
87                                 if (p.CommandType==CommandType)\r
88                                         return p;\r
89                         }\r
90                         throw new IndexOutOfRangeException();\r
91                 }\r
92 \r
93                 public Provider FindByDataAdapterType(Type DataAdapterType)\r
94                 {\r
95                         foreach (Provider p in this)\r
96                         {\r
97                                 if (p.DataAdapterType==DataAdapterType)\r
98                                         return p;\r
99                         }\r
100                         throw new IndexOutOfRangeException();\r
101                 }\r
102 \r
103                 public Provider FindByConnectionType(Type ConnectionType)\r
104                 {\r
105                         foreach (Provider p in this)\r
106                         {\r
107                                 if (p.ConnectionType==ConnectionType)\r
108                                         return p;\r
109                         }\r
110                         throw new IndexOutOfRangeException();\r
111                 }\r
112 \r
113                 /// <summary>\r
114                 ///    <para>Adds a <see cref='.Provider'/> with the specified value to the \r
115                 ///    <see cref='.ProviderCollection'/> .</para>\r
116                 /// </summary>\r
117                 /// <param name='value'>The <see cref='.Provider'/> to add.</param>\r
118                 /// <returns>\r
119                 ///    <para>The index at which the new element was inserted.</para>\r
120                 /// </returns>\r
121                 /// <seealso cref='.ProviderCollection.AddRange'/>\r
122                 public void Add(Provider value) \r
123                 {\r
124                         Dictionary.Add(value.Name, value);\r
125                 }\r
126                 \r
127                 /// <summary>\r
128                 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>\r
129                 /// </summary>\r
130                 /// <param name='value'>\r
131                 ///    An array of type <see cref='.Provider'/> containing the objects to add to the collection.\r
132                 /// </param>\r
133                 /// <returns>\r
134                 ///   <para>None.</para>\r
135                 /// </returns>\r
136                 /// <seealso cref='.ProviderCollection.Add'/>\r
137                 public void AddRange(Provider[] value) \r
138                 {\r
139                         for (int i = 0; (i < value.Length); i = (i + 1)) \r
140                         {\r
141                                 this.Add(value[i]);\r
142                         }\r
143                 }\r
144                 \r
145                 /// <summary>\r
146                 ///     <para>\r
147                 ///       Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.\r
148                 ///    </para>\r
149                 /// </summary>\r
150                 /// <param name='value'>\r
151                 ///    A <see cref='.ProviderCollection'/> containing the objects to add to the collection.\r
152                 /// </param>\r
153                 /// <returns>\r
154                 ///   <para>None.</para>\r
155                 /// </returns>\r
156                 /// <seealso cref='.ProviderCollection.Add'/>\r
157                 public void AddRange(ProviderCollection value) \r
158                 {\r
159                         foreach (Provider p in value)\r
160                         {\r
161                                 this.Add(p);\r
162                         }\r
163                 }\r
164                 \r
165                 /// <summary>\r
166                 /// <para>Gets a value indicating whether the \r
167                 ///    <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>\r
168                 /// </summary>\r
169                 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>\r
170                 /// <returns>\r
171                 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection; \r
172                 ///   otherwise, <see langword='false'/>.</para>\r
173                 /// </returns>\r
174                 /// <seealso cref='.ProviderCollection.IndexOf'/>\r
175                 public bool Contains(Provider value) \r
176                 {\r
177                         return Dictionary.Contains(value);\r
178                 }\r
179                 \r
180                 /// <summary>\r
181                 /// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the \r
182                 ///    specified index.</para>\r
183                 /// </summary>\r
184                 /// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='.ProviderCollection'/> .</para></param>\r
185                 /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>\r
186                 /// <returns>\r
187                 ///   <para>None.</para>\r
188                 /// </returns>\r
189                 /// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='.ProviderCollection'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>\r
190                 /// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>\r
191                 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>\r
192                 /// <seealso cref='System.Array'/>\r
193                 public void CopyTo(Provider[] array, int index) \r
194                 {\r
195                         Dictionary.CopyTo(array, index);\r
196                 }\r
197                 \r
198                 /// <summary>\r
199                 ///    <para>Returns an enumerator that can iterate through \r
200                 ///       the <see cref='.ProviderCollection'/> .</para>\r
201                 /// </summary>\r
202                 /// <returns><para>None.</para></returns>\r
203                 /// <seealso cref='System.Collections.IEnumerator'/>\r
204                 public new ProviderEnumerator GetEnumerator() \r
205                 {\r
206                         return new ProviderEnumerator(this);\r
207                 }\r
208                 \r
209                 /// <summary>\r
210                 ///    <para> Removes a specific <see cref='.Provider'/> from the \r
211                 ///    <see cref='.ProviderCollection'/> .</para>\r
212                 /// </summary>\r
213                 /// <param name='value'>The <see cref='.Provider'/> to remove from the <see cref='.ProviderCollection'/> .</param>\r
214                 /// <returns><para>None.</para></returns>\r
215                 /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>\r
216                 public void Remove(Provider value) \r
217                 {\r
218                         Dictionary.Remove(value);\r
219                 }\r
220                 \r
221                 public class ProviderEnumerator : object, IEnumerator \r
222                 {\r
223                         \r
224                         private IEnumerator baseEnumerator;\r
225                         \r
226                         private IEnumerable temp;\r
227                         \r
228                         public ProviderEnumerator(ProviderCollection mappings) \r
229                         {\r
230                                 this.temp = ((IEnumerable)(mappings));\r
231                                 this.baseEnumerator = temp.GetEnumerator();\r
232                         }\r
233                         \r
234                         public Provider Current \r
235                         {\r
236                                 get \r
237                                 {\r
238                                         return ((Provider) ((DictionaryEntry) (baseEnumerator.Current)).Value);\r
239                                 }\r
240                         }\r
241                         \r
242                         object IEnumerator.Current \r
243                         {\r
244                                 get \r
245                                 {\r
246                                         return baseEnumerator.Current;\r
247                                 }\r
248                         }\r
249                         \r
250                         public bool MoveNext() \r
251                         {\r
252                                 return baseEnumerator.MoveNext();\r
253                         }\r
254                         \r
255                         bool IEnumerator.MoveNext() \r
256                         {\r
257                                 return baseEnumerator.MoveNext();\r
258                         }\r
259                         \r
260                         public void Reset() \r
261                         {\r
262                                 baseEnumerator.Reset();\r
263                         }\r
264                         \r
265                         void IEnumerator.Reset() \r
266                         {\r
267                                 baseEnumerator.Reset();\r
268                         }\r
269                 }\r
270         }\r
271 }\r