1 //------------------------------------------------------------------------------
2 // <copyright file="CodeNamespaceImportCollection.cs" company="Microsoft">
4 // <OWNER>Microsoft</OWNER>
5 // Copyright (c) Microsoft Corporation. All rights reserved.
7 //------------------------------------------------------------------------------
9 namespace System.CodeDom {
11 using System.Diagnostics;
13 using System.Collections;
14 using System.Runtime.InteropServices;
15 using System.Globalization;
19 /// Manages a collection of <see cref='System.CodeDom.CodeNamespaceImport'/> objects.
23 ClassInterface(ClassInterfaceType.AutoDispatch),
27 public class CodeNamespaceImportCollection : IList {
28 private ArrayList data = new ArrayList();
29 private Hashtable keys = new Hashtable(StringComparer.OrdinalIgnoreCase);
33 /// Indexer method that provides collection access.
36 public CodeNamespaceImport this[int index] {
38 return ((CodeNamespaceImport)data[index]);
48 /// Gets or sets the number of namespaces in the collection.
67 bool IList.IsFixedSize
78 /// Adds a namespace import to the collection.
81 public void Add(CodeNamespaceImport value) {
82 if (!keys.ContainsKey(value.Namespace)) {
83 keys[value.Namespace] = value;
90 /// Adds a set of <see cref='System.CodeDom.CodeNamespaceImport'/> objects to the collection.
93 public void AddRange(CodeNamespaceImport[] value) {
95 throw new ArgumentNullException("value");
97 foreach (CodeNamespaceImport c in value) {
104 /// Clears the collection of members.
107 public void Clear() {
114 /// Makes the collection of keys synchronised with the data.
117 private void SyncKeys() {
118 keys = new Hashtable(StringComparer.OrdinalIgnoreCase);
119 foreach(CodeNamespaceImport c in this) {
120 keys[c.Namespace] = c;
126 /// Gets an enumerator that enumerates the collection members.
129 public IEnumerator GetEnumerator() {
130 return data.GetEnumerator();
134 object IList.this[int index] {
139 this[index] = (CodeNamespaceImport)value;
145 int ICollection.Count {
152 bool ICollection.IsSynchronized {
159 object ICollection.SyncRoot {
166 void ICollection.CopyTo(Array array, int index) {
167 data.CopyTo(array, index);
171 IEnumerator IEnumerable.GetEnumerator() {
172 return GetEnumerator();
176 int IList.Add(object value) {
177 return data.Add((CodeNamespaceImport)value);
186 bool IList.Contains(object value) {
187 return data.Contains(value);
191 int IList.IndexOf(object value) {
192 return data.IndexOf((CodeNamespaceImport)value);
196 void IList.Insert(int index, object value) {
197 data.Insert(index, (CodeNamespaceImport)value);
202 void IList.Remove(object value) {
203 data.Remove((CodeNamespaceImport)value);
208 void IList.RemoveAt(int index) {
209 data.RemoveAt(index);