2 // Mono.Data.ProviderCollection
\r
5 // Brian Ritchie (brianlritchie@hotmail.com)
\r
8 // Copyright (C) Brian Ritchie, 2002
\r
11 namespace Mono.Data
\r
14 using System.Collections;
\r
15 using System.Collections.Specialized;
\r
20 /// A collection that stores <see cref='.Provider'/> objects.
\r
23 /// <seealso cref='.ProviderCollection'/>
\r
25 public class ProviderCollection : DictionaryBase
\r
30 /// Initializes a new instance of <see cref='.ProviderCollection'/>.
\r
33 public ProviderCollection()
\r
39 /// Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.
\r
42 /// <param name='value'>
\r
43 /// A <see cref='.ProviderCollection'/> from which the contents are copied
\r
45 public ProviderCollection(ProviderCollection value)
\r
47 this.AddRange(value);
\r
52 /// Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
\r
55 /// <param name='value'>
\r
56 /// A array of <see cref='.Provider'/> objects with which to intialize the collection
\r
58 public ProviderCollection(Provider[] value)
\r
60 this.AddRange(value);
\r
64 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>
\r
66 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
\r
68 /// <para> The entry at the specified index of the collection.</para>
\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
75 return ((Provider)(Dictionary[Name]));
\r
79 Dictionary[Name] = value;
\r
83 public Provider FindByCommandType(Type CommandType)
\r
85 foreach (Provider p in this)
\r
87 if (p.CommandType==CommandType)
\r
90 throw new IndexOutOfRangeException();
\r
93 public Provider FindByDataAdapterType(Type DataAdapterType)
\r
95 foreach (Provider p in this)
\r
97 if (p.DataAdapterType==DataAdapterType)
\r
100 throw new IndexOutOfRangeException();
\r
103 public Provider FindByConnectionType(Type ConnectionType)
\r
105 foreach (Provider p in this)
\r
107 if (p.ConnectionType==ConnectionType)
\r
110 throw new IndexOutOfRangeException();
\r
114 /// <para>Adds a <see cref='.Provider'/> with the specified value to the
\r
115 /// <see cref='.ProviderCollection'/> .</para>
\r
117 /// <param name='value'>The <see cref='.Provider'/> to add.</param>
\r
119 /// <para>The index at which the new element was inserted.</para>
\r
121 /// <seealso cref='.ProviderCollection.AddRange'/>
\r
122 public void Add(Provider value)
\r
124 Dictionary.Add(value.Name, value);
\r
128 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
\r
130 /// <param name='value'>
\r
131 /// An array of type <see cref='.Provider'/> containing the objects to add to the collection.
\r
134 /// <para>None.</para>
\r
136 /// <seealso cref='.ProviderCollection.Add'/>
\r
137 public void AddRange(Provider[] value)
\r
139 for (int i = 0; (i < value.Length); i = (i + 1))
\r
141 this.Add(value[i]);
\r
147 /// Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.
\r
150 /// <param name='value'>
\r
151 /// A <see cref='.ProviderCollection'/> containing the objects to add to the collection.
\r
154 /// <para>None.</para>
\r
156 /// <seealso cref='.ProviderCollection.Add'/>
\r
157 public void AddRange(ProviderCollection value)
\r
159 foreach (Provider p in value)
\r
166 /// <para>Gets a value indicating whether the
\r
167 /// <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
\r
169 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>
\r
171 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection;
\r
172 /// otherwise, <see langword='false'/>.</para>
\r
174 /// <seealso cref='.ProviderCollection.IndexOf'/>
\r
175 public bool Contains(Provider value)
\r
177 return Dictionary.Contains(value);
\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
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
187 /// <para>None.</para>
\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
195 Dictionary.CopyTo(array, index);
\r
199 /// <para>Returns an enumerator that can iterate through
\r
200 /// the <see cref='.ProviderCollection'/> .</para>
\r
202 /// <returns><para>None.</para></returns>
\r
203 /// <seealso cref='System.Collections.IEnumerator'/>
\r
204 public new ProviderEnumerator GetEnumerator()
\r
206 return new ProviderEnumerator(this);
\r
210 /// <para> Removes a specific <see cref='.Provider'/> from the
\r
211 /// <see cref='.ProviderCollection'/> .</para>
\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
218 Dictionary.Remove(value);
\r
221 public class ProviderEnumerator : object, IEnumerator
\r
224 private IEnumerator baseEnumerator;
\r
226 private IEnumerable temp;
\r
228 public ProviderEnumerator(ProviderCollection mappings)
\r
230 this.temp = ((IEnumerable)(mappings));
\r
231 this.baseEnumerator = temp.GetEnumerator();
\r
234 public Provider Current
\r
238 return ((Provider) ((DictionaryEntry) (baseEnumerator.Current)).Value);
\r
242 object IEnumerator.Current
\r
246 return baseEnumerator.Current;
\r
250 public bool MoveNext()
\r
252 return baseEnumerator.MoveNext();
\r
255 bool IEnumerator.MoveNext()
\r
257 return baseEnumerator.MoveNext();
\r
260 public void Reset()
\r
262 baseEnumerator.Reset();
\r
265 void IEnumerator.Reset()
\r
267 baseEnumerator.Reset();
\r