2 // Mono.Data.ProviderCollection
\r
5 // Brian Ritchie (brianlritchie@hotmail.com)
\r
8 // Copyright (C) Brian Ritchie, 2002
\r
13 // Permission is hereby granted, free of charge, to any person obtaining
\r
14 // a copy of this software and associated documentation files (the
\r
15 // "Software"), to deal in the Software without restriction, including
\r
16 // without limitation the rights to use, copy, modify, merge, publish,
\r
17 // distribute, sublicense, and/or sell copies of the Software, and to
\r
18 // permit persons to whom the Software is furnished to do so, subject to
\r
19 // the following conditions:
\r
21 // The above copyright notice and this permission notice shall be
\r
22 // included in all copies or substantial portions of the Software.
\r
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 namespace Mono.Data
\r
35 using System.Collections;
\r
36 using System.Collections.Specialized;
\r
41 /// A collection that stores <see cref='.Provider'/> objects.
\r
44 /// <seealso cref='.ProviderCollection'/>
\r
46 public class ProviderCollection : DictionaryBase
\r
51 /// Initializes a new instance of <see cref='.ProviderCollection'/>.
\r
54 public ProviderCollection ()
\r
61 /// Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.
\r
64 /// <param name='value'>
\r
65 /// A <see cref='.ProviderCollection'/> from which the contents are copied
\r
67 public ProviderCollection (ProviderCollection value)
\r
70 throw new System.ArgumentNullException ("value");
\r
72 this.AddRange (value);
\r
77 /// Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
\r
80 /// <param name='value'>
\r
81 /// A array of <see cref='.Provider'/> objects with which to intialize the collection
\r
83 public ProviderCollection (Provider[] value)
\r
86 throw new System.ArgumentNullException ("value");
\r
88 this.AddRange (value);
\r
92 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>
\r
94 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
\r
96 /// <para> The entry at the specified index of the collection.</para>
\r
98 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
\r
99 public Provider this [string Name]
\r
102 return ((Provider)(Dictionary [Name]));
\r
105 Dictionary [Name] = value;
\r
109 public Provider FindByCommandType(Type CommandType)
\r
111 if (CommandType == null)
\r
112 throw new System.ArgumentNullException ("CommandType");
\r
114 foreach (Provider p in this) {
\r
115 if (p.CommandType == CommandType)
\r
118 throw new IndexOutOfRangeException ();
\r
121 public Provider FindByDataAdapterType(Type DataAdapterType)
\r
123 if (DataAdapterType == null)
\r
124 throw new System.ArgumentNullException ("DataAdapterType");
\r
126 foreach (Provider p in this) {
\r
127 if (p.DataAdapterType == DataAdapterType)
\r
130 throw new IndexOutOfRangeException ();
\r
133 public Provider FindByConnectionType(Type ConnectionType)
\r
135 if (ConnectionType == null)
\r
136 throw new System.ArgumentNullException("ConnectionType");
\r
138 foreach (Provider p in this) {
\r
139 if (p.ConnectionType == ConnectionType)
\r
142 throw new IndexOutOfRangeException ();
\r
146 /// <para>Adds a <see cref='.Provider'/> with the specified value to the
\r
147 /// <see cref='.ProviderCollection'/> .</para>
\r
149 /// <param name='value'>The <see cref='.Provider'/> to add.</param>
\r
151 /// <para>The index at which the new element was inserted.</para>
\r
153 /// <seealso cref='.ProviderCollection.AddRange'/>
\r
154 public void Add(Provider value)
\r
156 if (value == null)
\r
157 throw new System.ArgumentNullException ("value");
\r
159 Dictionary.Add (value.Name, value);
\r
163 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
\r
165 /// <param name='value'>
\r
166 /// An array of type <see cref='.Provider'/> containing the objects to add to the collection.
\r
169 /// <para>None.</para>
\r
171 /// <seealso cref='.ProviderCollection.Add'/>
\r
172 public void AddRange (Provider[] value)
\r
174 if (value == null)
\r
175 throw new System.ArgumentNullException ("value");
\r
177 for (int i = 0; i < value.Length; i++)
\r
178 this.Add (value [i]);
\r
183 /// Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.
\r
186 /// <param name='value'>
\r
187 /// A <see cref='.ProviderCollection'/> containing the objects to add to the collection.
\r
190 /// <para>None.</para>
\r
192 /// <seealso cref='.ProviderCollection.Add'/>
\r
193 public void AddRange(ProviderCollection value)
\r
195 if (value == null)
\r
196 throw new System.ArgumentNullException ("value");
\r
198 foreach (Provider p in value)
\r
203 /// <para>Gets a value indicating whether the
\r
204 /// <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
\r
206 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>
\r
208 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection;
\r
209 /// otherwise, <see langword='false'/>.</para>
\r
211 /// <seealso cref='.ProviderCollection.IndexOf'/>
\r
212 public bool Contains (Provider value)
\r
214 if (value == null)
\r
215 throw new System.ArgumentNullException("value");
\r
217 return Dictionary.Contains (value);
\r
221 /// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the
\r
222 /// specified index.</para>
\r
224 /// <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
225 /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
\r
227 /// <para>None.</para>
\r
229 /// <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
230 /// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
\r
231 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
\r
232 /// <seealso cref='System.Array'/>
\r
233 public void CopyTo(Provider[] array, int index)
\r
235 if (array == null)
\r
236 throw new System.ArgumentNullException ("array");
\r
238 Dictionary.CopyTo(array, index);
\r
242 /// <para>Returns an enumerator that can iterate through
\r
243 /// the <see cref='.ProviderCollection'/> .</para>
\r
245 /// <returns><para>None.</para></returns>
\r
246 /// <seealso cref='System.Collections.IEnumerator'/>
\r
247 public new ProviderEnumerator GetEnumerator ()
\r
249 return new ProviderEnumerator (this);
\r
253 /// <para> Removes a specific <see cref='.Provider'/> from the
\r
254 /// <see cref='.ProviderCollection'/> .</para>
\r
256 /// <param name='value'>The <see cref='.Provider'/> to remove from the <see cref='.ProviderCollection'/> .</param>
\r
257 /// <returns><para>None.</para></returns>
\r
258 /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
\r
259 public void Remove(Provider value)
\r
261 if (value == null)
\r
262 throw new System.ArgumentNullException ("value");
\r
264 Dictionary.Remove(value);
\r
267 public class ProviderEnumerator : object, IEnumerator
\r
270 private IEnumerator baseEnumerator;
\r
272 private IEnumerable temp;
\r
274 public ProviderEnumerator(ProviderCollection mappings)
\r
276 if (mappings == null)
\r
277 throw new System.ArgumentNullException ("mappings");
\r
279 this.temp = ((IEnumerable)(mappings));
\r
280 this.baseEnumerator = temp.GetEnumerator();
\r
283 public Provider Current
\r
287 return ((Provider) ((DictionaryEntry) (baseEnumerator.Current)).Value);
\r
291 object IEnumerator.Current
\r
295 return baseEnumerator.Current;
\r
299 public bool MoveNext()
\r
301 return baseEnumerator.MoveNext();
\r
304 bool IEnumerator.MoveNext()
\r
306 return baseEnumerator.MoveNext();
\r
309 public void Reset()
\r
311 baseEnumerator.Reset();
\r
314 void IEnumerator.Reset()
\r
316 baseEnumerator.Reset();
\r