2 // System.Configuration.Provider.ProviderCollection
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
34 namespace System.Configuration.Provider {
35 public class ProviderCollection : ICollection
37 public ProviderCollection ()
39 lookup = new Hashtable (10, StringComparer.InvariantCultureIgnoreCase);
40 values = new ArrayList ();
43 public virtual void Add (ProviderBase provider)
46 throw new NotSupportedException ();
48 if (provider == null || provider.Name == null)
49 throw new ArgumentNullException ();
51 int pos = values.Add (provider);
53 lookup.Add (provider.Name, pos);
55 values.RemoveAt (pos);
63 throw new NotSupportedException ();
68 public void CopyTo (ProviderBase[] array, int index)
70 values.CopyTo (array, index);
73 void ICollection.CopyTo (Array array, int index)
75 values.CopyTo (array, index);
78 public IEnumerator GetEnumerator ()
80 return values.GetEnumerator();
83 public void Remove (string name)
86 throw new NotSupportedException ();
88 object position = lookup [name];
90 if (position == null || !(position is int))
91 throw new ArgumentException ();
93 int pos = (int) position;
94 if (pos >= values.Count)
95 throw new ArgumentException ();
97 values.RemoveAt (pos);
100 ArrayList changed = new ArrayList ();
101 foreach (DictionaryEntry de in lookup) {
102 if ((int) de.Value <= pos)
104 changed.Add (de.Key);
107 foreach (string key in changed)
108 lookup [key] = (int)lookup [key] - 1;
111 public void SetReadOnly ()
116 public int Count { get { return values.Count; } }
117 public bool IsSynchronized { get { return false; } }
118 public object SyncRoot { get { return this; } }
120 public ProviderBase this [string name] {
122 object pos = lookup [name];
123 if (pos == null) return null;
125 return values [(int) pos] as ProviderBase;