2 // System.CodeDom CodeNamespaceImportCollection Class implementation
5 // Miguel de Icaza (miguel@ximian.com)
6 // Daniel Stodden (stodden@in.tum.de)
8 // (C) 2001 Ximian, Inc.
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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.
31 using System.Runtime.InteropServices;
32 using System.Collections;
34 namespace System.CodeDom
37 * Should probably be derived from CollectionBase like any
38 * other System.CodeDom.*Collection. MS docs say it currently
39 * is not, for whichever reason.
42 [ClassInterface(ClassInterfaceType.AutoDispatch)]
44 public class CodeNamespaceImportCollection
45 : IList, ICollection, IEnumerable
47 private Hashtable keys;
48 private ArrayList data;
53 public CodeNamespaceImportCollection ()
55 data = new ArrayList ();
56 keys = new Hashtable (CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
62 int ICollection.Count {
74 public CodeNamespaceImport this [int index] {
76 return (CodeNamespaceImport)data[index];
79 CodeNamespaceImport oldImport = (CodeNamespaceImport) data [index];
80 CodeNamespaceImport newImport = (CodeNamespaceImport) value;
81 keys.Remove (oldImport.Namespace);
83 keys [newImport.Namespace] = newImport;
90 public void Add (CodeNamespaceImport value)
93 throw new NullReferenceException ();
96 if (!keys.ContainsKey (value.Namespace)) {
97 keys [value.Namespace] = value;
102 public void AddRange (CodeNamespaceImport [] value)
105 throw new ArgumentNullException ("value");
108 foreach (CodeNamespaceImport elem in value) {
124 // IList implementation
125 bool IList.IsFixedSize {
131 bool IList.IsReadOnly {
137 object IList.this[int index] {
142 this [index] = (CodeNamespaceImport) value;
146 int IList.Add( object value )
148 Add ((CodeNamespaceImport) value);
149 return data.Count - 1;
152 bool IList.Contains( object value )
154 return data.Contains( value );
157 int IList.IndexOf( object value )
159 return data.IndexOf( value );
162 void IList.Insert( int index, object value )
164 data.Insert( index, value );
165 CodeNamespaceImport import = (CodeNamespaceImport) value;
166 keys [import.Namespace] = import;
169 void IList.Remove( object value )
171 string ns = ((CodeNamespaceImport)value).Namespace;
172 data.Remove( value );
173 foreach (CodeNamespaceImport import in data) {
174 if (import.Namespace == ns) {
182 void IList.RemoveAt( int index )
184 string ns = this [index].Namespace;
185 data.RemoveAt( index );
186 foreach (CodeNamespaceImport import in data) {
187 if (import.Namespace == ns) {
195 // ICollection implementation
196 object ICollection.SyncRoot {
202 bool ICollection.IsSynchronized {
204 return data.IsSynchronized;
208 void ICollection.CopyTo( Array array, int index )
210 data.CopyTo( array, index );
213 // IEnumerable implementation
214 IEnumerator IEnumerable.GetEnumerator ()
216 return data.GetEnumerator();
219 // IEnumerable implementation
220 public IEnumerator GetEnumerator ()
222 return data.GetEnumerator();