[System] Process.WaitForExit now triggers event Exited.
[mono.git] / mcs / class / System / System.CodeDom / CodeNamespaceImportCollection.cs
1 //
2 // System.CodeDom CodeNamespaceImportCollection Class implementation
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Daniel Stodden (stodden@in.tum.de)
7 //
8 // (C) 2001 Ximian, Inc.
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System.Runtime.InteropServices;
32 using System.Collections;
33
34 namespace System.CodeDom
35 {
36         /*
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.
40          */
41         [Serializable]
42         [ClassInterface(ClassInterfaceType.AutoDispatch)]
43         [ComVisible(true)]
44         public class CodeNamespaceImportCollection
45                 : IList, ICollection, IEnumerable
46         {
47                 private Hashtable keys;
48                 private ArrayList data;
49
50                 //
51                 // Constructors
52                 //
53                 public CodeNamespaceImportCollection ()
54                 {
55                         data = new ArrayList ();
56                         keys = new Hashtable (CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
57                 }
58
59                 //
60                 // Properties
61                 //
62                 int ICollection.Count {
63                         get {
64                                 return data.Count;
65                         }
66                 }
67                 
68                 public int Count {
69                         get {
70                                 return data.Count;
71                         }
72                 }
73
74                 public CodeNamespaceImport this [int index] {
75                         get {
76                                 return (CodeNamespaceImport)data[index];
77                         }
78                         set {
79                                 CodeNamespaceImport oldImport = (CodeNamespaceImport) data [index];
80                                 CodeNamespaceImport newImport = (CodeNamespaceImport) value;
81                                 keys.Remove (oldImport.Namespace);
82                                 data[index] = value;
83                                 keys [newImport.Namespace] = newImport;
84                         }
85                 }
86
87                 //
88                 // Methods
89                 //
90                 public void Add (CodeNamespaceImport value)
91                 {
92                         if (value == null) {
93                                 throw new NullReferenceException ();
94                         }
95
96                         if (!keys.ContainsKey (value.Namespace)) {
97                                 keys [value.Namespace] = value;
98                                 data.Add (value);
99                         }
100                 }
101
102                 public void AddRange (CodeNamespaceImport [] value)
103                 {
104                         if (value == null) {
105                                 throw new ArgumentNullException ("value");
106                         }
107
108                         foreach (CodeNamespaceImport elem in value) {
109                                 Add (elem);
110                         }
111                 }
112
113                 void IList.Clear ()
114                 {
115                         Clear ();
116                 }
117                 
118                 public void Clear ()
119                 {
120                         data.Clear ();
121                         keys.Clear ();
122                 }
123
124                 // IList implementation
125                 bool IList.IsFixedSize {
126                         get {
127                                 return false;
128                         }
129                 }
130
131                 bool IList.IsReadOnly {
132                         get {
133                                 return false;
134                         }
135                 }
136
137                 object IList.this[int index] {
138                         get {
139                                 return data[index];
140                         }
141                         set {
142                                 this [index] = (CodeNamespaceImport) value;
143                         }
144                 }
145
146                 int IList.Add( object value )
147                 {
148                         Add ((CodeNamespaceImport) value);
149                         return data.Count - 1;
150                 }
151                 
152                 bool IList.Contains( object value )
153                 {
154                         return data.Contains( value );
155                 }
156                 
157                 int IList.IndexOf( object value )
158                 {
159                         return data.IndexOf( value );
160                 }
161
162                 void IList.Insert( int index, object value )
163                 {
164                         data.Insert( index, value );
165                         CodeNamespaceImport import = (CodeNamespaceImport) value;
166                         keys [import.Namespace] = import;
167                 }
168
169                 void IList.Remove( object value )
170                 {
171                         string ns = ((CodeNamespaceImport)value).Namespace;
172                         data.Remove( value );
173                         foreach (CodeNamespaceImport import in data) {
174                                 if (import.Namespace == ns) {
175                                         keys [ns] = import;
176                                         return;
177                                 }
178                         }
179                         keys.Remove (ns);
180                 }
181                 
182                 void IList.RemoveAt( int index )
183                 {
184                         string ns = this [index].Namespace;
185                         data.RemoveAt( index );
186                         foreach (CodeNamespaceImport import in data) {
187                                 if (import.Namespace == ns) {
188                                         keys [ns] = import;
189                                         return;
190                                 }
191                         }
192                         keys.Remove (ns);
193                 }
194
195                 // ICollection implementation
196                 object ICollection.SyncRoot {
197                         get {
198                                 return null;
199                         }
200                 }
201
202                 bool ICollection.IsSynchronized {
203                         get {
204                                 return data.IsSynchronized;
205                         }
206                 }
207
208                 void ICollection.CopyTo( Array array, int index )
209                 {
210                         data.CopyTo( array, index );
211                 }
212
213                 // IEnumerable implementation
214                 IEnumerator IEnumerable.GetEnumerator ()
215                 {
216                         return data.GetEnumerator();
217                 }
218                 
219                 // IEnumerable implementation
220                 public IEnumerator GetEnumerator ()
221                 {
222                         return data.GetEnumerator();
223                 }
224         }
225 }