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
60 /// Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.
\r
63 /// <param name='value'>
\r
64 /// A <see cref='.ProviderCollection'/> from which the contents are copied
\r
66 public ProviderCollection(ProviderCollection value)
\r
68 this.AddRange(value);
\r
73 /// Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
\r
76 /// <param name='value'>
\r
77 /// A array of <see cref='.Provider'/> objects with which to intialize the collection
\r
79 public ProviderCollection(Provider[] value)
\r
81 this.AddRange(value);
\r
85 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>
\r
87 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
\r
89 /// <para> The entry at the specified index of the collection.</para>
\r
91 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
\r
92 public Provider this[string Name]
\r
96 return ((Provider)(Dictionary[Name]));
\r
100 Dictionary[Name] = value;
\r
104 public Provider FindByCommandType(Type CommandType)
\r
106 foreach (Provider p in this)
\r
108 if (p.CommandType==CommandType)
\r
111 throw new IndexOutOfRangeException();
\r
114 public Provider FindByDataAdapterType(Type DataAdapterType)
\r
116 foreach (Provider p in this)
\r
118 if (p.DataAdapterType==DataAdapterType)
\r
121 throw new IndexOutOfRangeException();
\r
124 public Provider FindByConnectionType(Type ConnectionType)
\r
126 foreach (Provider p in this)
\r
128 if (p.ConnectionType==ConnectionType)
\r
131 throw new IndexOutOfRangeException();
\r
135 /// <para>Adds a <see cref='.Provider'/> with the specified value to the
\r
136 /// <see cref='.ProviderCollection'/> .</para>
\r
138 /// <param name='value'>The <see cref='.Provider'/> to add.</param>
\r
140 /// <para>The index at which the new element was inserted.</para>
\r
142 /// <seealso cref='.ProviderCollection.AddRange'/>
\r
143 public void Add(Provider value)
\r
145 Dictionary.Add(value.Name, value);
\r
149 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
\r
151 /// <param name='value'>
\r
152 /// An array of type <see cref='.Provider'/> containing the objects to add to the collection.
\r
155 /// <para>None.</para>
\r
157 /// <seealso cref='.ProviderCollection.Add'/>
\r
158 public void AddRange(Provider[] value)
\r
160 for (int i = 0; (i < value.Length); i = (i + 1))
\r
162 this.Add(value[i]);
\r
168 /// Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.
\r
171 /// <param name='value'>
\r
172 /// A <see cref='.ProviderCollection'/> containing the objects to add to the collection.
\r
175 /// <para>None.</para>
\r
177 /// <seealso cref='.ProviderCollection.Add'/>
\r
178 public void AddRange(ProviderCollection value)
\r
180 foreach (Provider p in value)
\r
187 /// <para>Gets a value indicating whether the
\r
188 /// <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
\r
190 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>
\r
192 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection;
\r
193 /// otherwise, <see langword='false'/>.</para>
\r
195 /// <seealso cref='.ProviderCollection.IndexOf'/>
\r
196 public bool Contains(Provider value)
\r
198 return Dictionary.Contains(value);
\r
202 /// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the
\r
203 /// specified index.</para>
\r
205 /// <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
206 /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
\r
208 /// <para>None.</para>
\r
210 /// <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
211 /// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
\r
212 /// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
\r
213 /// <seealso cref='System.Array'/>
\r
214 public void CopyTo(Provider[] array, int index)
\r
216 Dictionary.CopyTo(array, index);
\r
220 /// <para>Returns an enumerator that can iterate through
\r
221 /// the <see cref='.ProviderCollection'/> .</para>
\r
223 /// <returns><para>None.</para></returns>
\r
224 /// <seealso cref='System.Collections.IEnumerator'/>
\r
225 public new ProviderEnumerator GetEnumerator()
\r
227 return new ProviderEnumerator(this);
\r
231 /// <para> Removes a specific <see cref='.Provider'/> from the
\r
232 /// <see cref='.ProviderCollection'/> .</para>
\r
234 /// <param name='value'>The <see cref='.Provider'/> to remove from the <see cref='.ProviderCollection'/> .</param>
\r
235 /// <returns><para>None.</para></returns>
\r
236 /// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
\r
237 public void Remove(Provider value)
\r
239 Dictionary.Remove(value);
\r
242 public class ProviderEnumerator : object, IEnumerator
\r
245 private IEnumerator baseEnumerator;
\r
247 private IEnumerable temp;
\r
249 public ProviderEnumerator(ProviderCollection mappings)
\r
251 this.temp = ((IEnumerable)(mappings));
\r
252 this.baseEnumerator = temp.GetEnumerator();
\r
255 public Provider Current
\r
259 return ((Provider) ((DictionaryEntry) (baseEnumerator.Current)).Value);
\r
263 object IEnumerator.Current
\r
267 return baseEnumerator.Current;
\r
271 public bool MoveNext()
\r
273 return baseEnumerator.MoveNext();
\r
276 bool IEnumerator.MoveNext()
\r
278 return baseEnumerator.MoveNext();
\r
281 public void Reset()
\r
283 baseEnumerator.Reset();
\r
286 void IEnumerator.Reset()
\r
288 baseEnumerator.Reset();
\r