Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System / compmod / system / codedom / CodeNamespaceImportCollection.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CodeNamespaceImportCollection.cs" company="Microsoft">
3 // 
4 // <OWNER>Microsoft</OWNER>
5 //     Copyright (c) Microsoft Corporation.  All rights reserved.
6 // </copyright>                                                                
7 //------------------------------------------------------------------------------
8
9 namespace System.CodeDom {
10
11     using System.Diagnostics;
12     using System;
13     using System.Collections;
14     using System.Runtime.InteropServices;
15     using System.Globalization;
16     
17     /// <devdoc>
18     ///    <para>
19     ///       Manages a collection of <see cref='System.CodeDom.CodeNamespaceImport'/> objects.
20     ///    </para>
21     /// </devdoc>
22     [
23         ClassInterface(ClassInterfaceType.AutoDispatch),
24         ComVisible(true),
25         Serializable,
26     ]
27     public class CodeNamespaceImportCollection : IList {
28         private ArrayList data = new ArrayList();
29         private Hashtable keys = new Hashtable(StringComparer.OrdinalIgnoreCase);
30
31         /// <devdoc>
32         ///    <para>
33         ///       Indexer method that provides collection access.
34         ///    </para>
35         /// </devdoc>
36         public CodeNamespaceImport this[int index] {
37             get {
38                 return ((CodeNamespaceImport)data[index]);
39             }
40             set {
41                 data[index] = value;
42                 SyncKeys();
43             }
44         }
45
46         /// <devdoc>
47         ///    <para>
48         ///       Gets or sets the number of namespaces in the collection.
49         ///    </para>
50         /// </devdoc>
51         public int Count {
52             get {
53                 return data.Count;
54             }
55         }
56
57                 /// <internalonly/>
58                 bool IList.IsReadOnly
59                 {
60                         get
61                         {
62                                 return false;
63                         }
64                 }
65
66                 /// <internalonly/>
67                 bool IList.IsFixedSize
68                 {
69                         get
70                         {
71                                 return false;
72                         }
73                 }
74
75
76         /// <devdoc>
77         ///    <para>
78         ///       Adds a namespace import to the collection.
79         ///    </para>
80         /// </devdoc>
81         public void Add(CodeNamespaceImport value) {
82             if (!keys.ContainsKey(value.Namespace)) {
83                 keys[value.Namespace] = value;
84                 data.Add(value);
85             }
86         }
87
88         /// <devdoc>
89         ///    <para>
90         ///       Adds a set of <see cref='System.CodeDom.CodeNamespaceImport'/> objects to the collection.
91         ///    </para>
92         /// </devdoc>
93         public void AddRange(CodeNamespaceImport[] value) {
94             if (value == null) {
95                 throw new ArgumentNullException("value");
96             }
97             foreach (CodeNamespaceImport c in value) {
98                 Add(c);
99             }
100         }
101
102         /// <devdoc>
103         ///    <para>
104         ///       Clears the collection of members.
105         ///    </para>
106         /// </devdoc>
107         public void Clear() {
108             data.Clear();
109             keys.Clear();
110         }
111
112         /// <devdoc>
113         ///    <para>
114         ///    Makes the collection of keys synchronised with the data.
115         ///    </para>
116         /// </devdoc>
117         private void SyncKeys() {
118             keys = new Hashtable(StringComparer.OrdinalIgnoreCase);
119             foreach(CodeNamespaceImport c in this) {
120                 keys[c.Namespace] = c;
121             }
122         }
123
124         /// <devdoc>
125         ///    <para>
126         ///       Gets an enumerator that enumerates the collection members.
127         ///    </para>
128         /// </devdoc>
129         public IEnumerator GetEnumerator() {
130             return data.GetEnumerator();
131         }
132
133         /// <internalonly/>
134         object IList.this[int index] {
135             get {
136                 return this[index];
137             }
138             set {
139                 this[index] = (CodeNamespaceImport)value;
140                 SyncKeys();
141             }
142         }
143
144         /// <internalonly/>
145         int ICollection.Count {
146             get {
147                 return Count;
148             }
149         }
150
151         /// <internalonly/>
152         bool ICollection.IsSynchronized {
153             get {
154                 return false;
155             }
156         }
157
158         /// <internalonly/>
159         object ICollection.SyncRoot {
160             get {
161                 return null;
162             }
163         }
164
165         /// <internalonly/>
166         void ICollection.CopyTo(Array array, int index) {
167             data.CopyTo(array, index);
168         }
169
170         /// <internalonly/>
171         IEnumerator IEnumerable.GetEnumerator() {
172             return GetEnumerator();
173         }
174
175         /// <internalonly/>
176         int IList.Add(object value) {
177             return data.Add((CodeNamespaceImport)value);
178         }
179
180         /// <internalonly/>
181         void IList.Clear() {
182             Clear();
183         }
184
185         /// <internalonly/>
186         bool IList.Contains(object value) {
187             return data.Contains(value);
188         }
189
190         /// <internalonly/>
191         int IList.IndexOf(object value) {
192             return data.IndexOf((CodeNamespaceImport)value);
193         }
194
195         /// <internalonly/>
196         void IList.Insert(int index, object value) {
197             data.Insert(index, (CodeNamespaceImport)value);
198             SyncKeys();
199         }
200
201         /// <internalonly/>
202         void IList.Remove(object value) {
203             data.Remove((CodeNamespaceImport)value);
204             SyncKeys();
205         }
206
207         /// <internalonly/>
208         void IList.RemoveAt(int index) {
209             data.RemoveAt(index);
210             SyncKeys();
211         }
212     }
213 }
214
215