2009-11-12 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Mono.Data / ProviderCollection.cs
blob0cadc51aa57766a112af033421796a0f10b5eed2
1 //
2 // Mono.Data.ProviderCollection
3 //
4 // Authors:
5 // Brian Ritchie (brianlritchie@hotmail.com)
6 //
7 //
8 // Copyright (C) Brian Ritchie, 2002
9 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace Mono.Data
34 using System;
35 using System.Collections;
36 using System.Collections.Specialized;
39 /// <summary>
40 /// <para>
41 /// A collection that stores <see cref='.Provider'/> objects.
42 /// </para>
43 /// </summary>
44 /// <seealso cref='.ProviderCollection'/>
45 [Serializable ()]
46 #if NET_2_0
47 [Obsolete("ProviderFactory in assembly Mono.Data has been made obsolete by DbProviderFactories in assembly System.Data.")]
48 #endif
49 public class ProviderCollection : DictionaryBase
52 /// <summary>
53 /// <para>
54 /// Initializes a new instance of <see cref='.ProviderCollection'/>.
55 /// </para>
56 /// </summary>
57 public ProviderCollection ()
62 /// <summary>
63 /// <para>
64 /// Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.
65 /// </para>
66 /// </summary>
67 /// <param name='value'>
68 /// A <see cref='.ProviderCollection'/> from which the contents are copied
69 /// </param>
70 public ProviderCollection (ProviderCollection value)
72 if (value == null)
73 throw new System.ArgumentNullException ("value");
75 this.AddRange (value);
78 /// <summary>
79 /// <para>
80 /// Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
81 /// </para>
82 /// </summary>
83 /// <param name='value'>
84 /// A array of <see cref='.Provider'/> objects with which to intialize the collection
85 /// </param>
86 public ProviderCollection (Provider[] value)
88 if (value == null)
89 throw new System.ArgumentNullException ("value");
91 this.AddRange (value);
94 /// <summary>
95 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>
96 /// </summary>
97 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
98 /// <value>
99 /// <para> The entry at the specified index of the collection.</para>
100 /// </value>
101 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
102 public Provider this [string Name]
104 get {
105 return ((Provider)(Dictionary [Name]));
107 set {
108 Dictionary [Name] = value;
112 public Provider FindByCommandType(Type CommandType)
114 if (CommandType == null)
115 throw new System.ArgumentNullException ("CommandType");
117 foreach (Provider p in this) {
118 if (p.CommandType == CommandType)
119 return p;
121 throw new IndexOutOfRangeException ();
124 public Provider FindByDataAdapterType(Type DataAdapterType)
126 if (DataAdapterType == null)
127 throw new System.ArgumentNullException ("DataAdapterType");
129 foreach (Provider p in this) {
130 if (p.DataAdapterType == DataAdapterType)
131 return p;
133 throw new IndexOutOfRangeException ();
136 public Provider FindByConnectionType(Type ConnectionType)
138 if (ConnectionType == null)
139 throw new System.ArgumentNullException("ConnectionType");
141 foreach (Provider p in this) {
142 if (p.ConnectionType == ConnectionType)
143 return p;
145 throw new IndexOutOfRangeException ();
148 /// <summary>
149 /// <para>Adds a <see cref='.Provider'/> with the specified value to the
150 /// <see cref='.ProviderCollection'/> .</para>
151 /// </summary>
152 /// <param name='value'>The <see cref='.Provider'/> to add.</param>
153 /// <returns>
154 /// <para>The index at which the new element was inserted.</para>
155 /// </returns>
156 /// <seealso cref='.ProviderCollection.AddRange'/>
157 public void Add(Provider value)
159 if (value == null)
160 throw new System.ArgumentNullException ("value");
162 Dictionary.Add (value.Name, value);
165 /// <summary>
166 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
167 /// </summary>
168 /// <param name='value'>
169 /// An array of type <see cref='.Provider'/> containing the objects to add to the collection.
170 /// </param>
171 /// <returns>
172 /// <para>None.</para>
173 /// </returns>
174 /// <seealso cref='.ProviderCollection.Add'/>
175 public void AddRange (Provider[] value)
177 if (value == null)
178 throw new System.ArgumentNullException ("value");
180 for (int i = 0; i < value.Length; i++)
181 this.Add (value [i]);
184 /// <summary>
185 /// <para>
186 /// Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.
187 /// </para>
188 /// </summary>
189 /// <param name='value'>
190 /// A <see cref='.ProviderCollection'/> containing the objects to add to the collection.
191 /// </param>
192 /// <returns>
193 /// <para>None.</para>
194 /// </returns>
195 /// <seealso cref='.ProviderCollection.Add'/>
196 public void AddRange(ProviderCollection value)
198 if (value == null)
199 throw new System.ArgumentNullException ("value");
201 foreach (Provider p in value)
202 this.Add (p);
205 /// <summary>
206 /// <para>Gets a value indicating whether the
207 /// <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
208 /// </summary>
209 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>
210 /// <returns>
211 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection;
212 /// otherwise, <see langword='false'/>.</para>
213 /// </returns>
214 /// <seealso cref='.ProviderCollection.IndexOf'/>
215 public bool Contains (Provider value)
217 if (value == null)
218 throw new System.ArgumentNullException("value");
220 return Dictionary.Contains (value);
223 /// <summary>
224 /// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the
225 /// specified index.</para>
226 /// </summary>
227 /// <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>
228 /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
229 /// <returns>
230 /// <para>None.</para>
231 /// </returns>
232 /// <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>
233 /// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
234 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
235 /// <seealso cref='System.Array'/>
236 public void CopyTo(Provider[] array, int index)
238 if (array == null)
239 throw new System.ArgumentNullException ("array");
241 Dictionary.CopyTo(array, index);
244 /// <summary>
245 /// <para>Returns an enumerator that can iterate through
246 /// the <see cref='.ProviderCollection'/> .</para>
247 /// </summary>
248 /// <returns><para>None.</para></returns>
249 /// <seealso cref='System.Collections.IEnumerator'/>
250 public new ProviderEnumerator GetEnumerator ()
252 return new ProviderEnumerator (this);
255 /// <summary>
256 /// <para> Removes a specific <see cref='.Provider'/> from the
257 /// <see cref='.ProviderCollection'/> .</para>
258 /// </summary>
259 /// <param name='value'>The <see cref='.Provider'/> to remove from the <see cref='.ProviderCollection'/> .</param>
260 /// <returns><para>None.</para></returns>
261 /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
262 public void Remove(Provider value)
264 if (value == null)
265 throw new System.ArgumentNullException ("value");
267 Dictionary.Remove(value);
270 public class ProviderEnumerator : object, IEnumerator
273 private IEnumerator baseEnumerator;
275 private IEnumerable temp;
277 public ProviderEnumerator(ProviderCollection mappings)
279 if (mappings == null)
280 throw new System.ArgumentNullException ("mappings");
282 this.temp = ((IEnumerable)(mappings));
283 this.baseEnumerator = temp.GetEnumerator();
286 public Provider Current
288 get
290 return ((Provider) ((DictionaryEntry) (baseEnumerator.Current)).Value);
294 object IEnumerator.Current
296 get
298 return baseEnumerator.Current;
302 public bool MoveNext()
304 return baseEnumerator.MoveNext();
307 bool IEnumerator.MoveNext()
309 return baseEnumerator.MoveNext();
312 public void Reset()
314 baseEnumerator.Reset();
317 void IEnumerator.Reset()
319 baseEnumerator.Reset();