2 // Mono.Data.ProviderCollection
5 // Brian Ritchie (brianlritchie@hotmail.com)
8 // Copyright (C) Brian Ritchie, 2002
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:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
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.
35 using System
.Collections
;
36 using System
.Collections
.Specialized
;
41 /// A collection that stores <see cref='.Provider'/> objects.
44 /// <seealso cref='.ProviderCollection'/>
47 [Obsolete("ProviderFactory in assembly Mono.Data has been made obsolete by DbProviderFactories in assembly System.Data.")]
49 public class ProviderCollection
: DictionaryBase
54 /// Initializes a new instance of <see cref='.ProviderCollection'/>.
57 public ProviderCollection ()
64 /// Initializes a new instance of <see cref='.ProviderCollection'/> based on another <see cref='.ProviderCollection'/>.
67 /// <param name='value'>
68 /// A <see cref='.ProviderCollection'/> from which the contents are copied
70 public ProviderCollection (ProviderCollection
value)
73 throw new System
.ArgumentNullException ("value");
75 this.AddRange (value);
80 /// Initializes a new instance of <see cref='.ProviderCollection'/> containing any array of <see cref='.Provider'/> objects.
83 /// <param name='value'>
84 /// A array of <see cref='.Provider'/> objects with which to intialize the collection
86 public ProviderCollection (Provider
[] value)
89 throw new System
.ArgumentNullException ("value");
91 this.AddRange (value);
95 /// <para>Represents the entry at the specified index of the <see cref='.Provider'/>.</para>
97 /// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
99 /// <para> The entry at the specified index of the collection.</para>
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
]
105 return ((Provider
)(Dictionary
[Name
]));
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
)
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
)
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
)
145 throw new IndexOutOfRangeException ();
149 /// <para>Adds a <see cref='.Provider'/> with the specified value to the
150 /// <see cref='.ProviderCollection'/> .</para>
152 /// <param name='value'>The <see cref='.Provider'/> to add.</param>
154 /// <para>The index at which the new element was inserted.</para>
156 /// <seealso cref='.ProviderCollection.AddRange'/>
157 public void Add(Provider
value)
160 throw new System
.ArgumentNullException ("value");
162 Dictionary
.Add (value.Name
, value);
166 /// <para>Copies the elements of an array to the end of the <see cref='.ProviderCollection'/>.</para>
168 /// <param name='value'>
169 /// An array of type <see cref='.Provider'/> containing the objects to add to the collection.
172 /// <para>None.</para>
174 /// <seealso cref='.ProviderCollection.Add'/>
175 public void AddRange (Provider
[] value)
178 throw new System
.ArgumentNullException ("value");
180 for (int i
= 0; i
< value.Length
; i
++)
181 this.Add (value [i
]);
186 /// Adds the contents of another <see cref='.ProviderCollection'/> to the end of the collection.
189 /// <param name='value'>
190 /// A <see cref='.ProviderCollection'/> containing the objects to add to the collection.
193 /// <para>None.</para>
195 /// <seealso cref='.ProviderCollection.Add'/>
196 public void AddRange(ProviderCollection
value)
199 throw new System
.ArgumentNullException ("value");
201 foreach (Provider p
in value)
206 /// <para>Gets a value indicating whether the
207 /// <see cref='.ProviderCollection'/> contains the specified <see cref='.Provider'/>.</para>
209 /// <param name='value'>The <see cref='.Provider'/> to locate.</param>
211 /// <para><see langword='true'/> if the <see cref='.Provider'/> is contained in the collection;
212 /// otherwise, <see langword='false'/>.</para>
214 /// <seealso cref='.ProviderCollection.IndexOf'/>
215 public bool Contains (Provider
value)
218 throw new System
.ArgumentNullException("value");
220 return Dictionary
.Contains (value);
224 /// <para>Copies the <see cref='.ProviderCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the
225 /// specified index.</para>
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>
230 /// <para>None.</para>
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
)
239 throw new System
.ArgumentNullException ("array");
241 Dictionary
.CopyTo(array
, index
);
245 /// <para>Returns an enumerator that can iterate through
246 /// the <see cref='.ProviderCollection'/> .</para>
248 /// <returns><para>None.</para></returns>
249 /// <seealso cref='System.Collections.IEnumerator'/>
250 public new ProviderEnumerator
GetEnumerator ()
252 return new ProviderEnumerator (this);
256 /// <para> Removes a specific <see cref='.Provider'/> from the
257 /// <see cref='.ProviderCollection'/> .</para>
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)
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
290 return ((Provider
) ((DictionaryEntry
) (baseEnumerator
.Current
)).Value
);
294 object IEnumerator
.Current
298 return baseEnumerator
.Current
;
302 public bool MoveNext()
304 return baseEnumerator
.MoveNext();
307 bool IEnumerator
.MoveNext()
309 return baseEnumerator
.MoveNext();
314 baseEnumerator
.Reset();
317 void IEnumerator
.Reset()
319 baseEnumerator
.Reset();