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, CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
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 (Array array, int index)
70 values.CopyTo (array, index);
73 public IEnumerator GetEnumerator ()
75 return values.GetEnumerator();
78 public void Remove (string name)
81 throw new NotSupportedException ();
83 object position = lookup [name];
85 if (position == null || !(position is int))
86 throw new ArgumentException ();
88 int pos = (int) position;
89 if (pos >= values.Count)
90 throw new ArgumentException ();
92 values.RemoveAt (pos);
95 ArrayList changed = new ArrayList ();
96 foreach (DictionaryEntry de in lookup) {
97 if ((int) de.Value <= pos)
102 foreach (string key in changed)
103 lookup [key] = (int)lookup [key] - 1;
106 public void SetReadOnly ()
111 public int Count { get { return values.Count; } }
112 public bool IsSynchronized { get { return false; } }
113 public object SyncRoot { get { return this; } }
115 public ProviderBase this [string name] {
117 object pos = lookup [name];
118 if (pos == null) return null;
120 return values [(int) pos] as ProviderBase;