Debian Codegraph @

mcs/tools/cil-strip/Mono.Cecil/ExternTypeCollection.cs

raw
1 //
2 // ExternTypeCollection.cs
3 //
4 // Author:
5 // Jb Evain ([email protected])
6 //
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Fri Mar 30 18:43:57 +0200 2007
9 //
10 // (C) 2005 Jb Evain
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 namespace Mono.Cecil {
33
34 using System;
35 using System.Collections;
36 using System.Collections.Specialized;
37
38 using Mono.Cecil.Cil;
39
40 using Hcp = Mono.Cecil.HashCodeProvider;
41 using Cmp = System.Collections.Comparer;
42
43 internal sealed class ExternTypeCollection : NameObjectCollectionBase, IList, IReflectionVisitable {
44
45 ModuleDefinition m_container;
46
47 public TypeReference this [int index] {
48 get { return this.BaseGet (index) as TypeReference; }
49 set { this.BaseSet (index, value); }
50 }
51
52 public TypeReference this [string fullName] {
53 get { return this.BaseGet (fullName) as TypeReference; }
54 set { this.BaseSet (fullName, value); }
55 }
56
57 public ModuleDefinition Container {
58 get { return m_container; }
59 }
60
61 public bool IsSynchronized {
62 get { return false; }
63 }
64
65 public object SyncRoot {
66 get { return this; }
67 }
68
69 bool IList.IsReadOnly {
70 get { return false; }
71 }
72
73 bool IList.IsFixedSize {
74 get { return false; }
75 }
76
77 object IList.this [int index] {
78 get { return BaseGet (index); }
79 set {
80 Check (value);
81 BaseSet (index, value);
82 }
83 }
84
85 public ExternTypeCollection (ModuleDefinition container) :
86 base (Hcp.Instance, Cmp.Default)
87 {
88 m_container = container;
89 }
90
91 public void Add (TypeReference value)
92 {
93 if (value == null)
94 throw new ArgumentNullException ("value");
95
96 this.BaseAdd (value.FullName, value);
97 }
98
99 public void Clear ()
100 {
101 this.BaseClear ();
102 }
103
104 public bool Contains (TypeReference value)
105 {
106 return Contains (value.FullName);
107 }
108
109 public bool Contains (string fullName)
110 {
111 return this.BaseGet (fullName) != null;
112 }
113
114 public int IndexOf (TypeReference value)
115 {
116 string [] keys = this.BaseGetAllKeys ();
117 return Array.IndexOf (keys, value.FullName, 0, keys.Length);
118 }
119
120 public void Remove (TypeReference value)
121 {
122 this.BaseRemove (value.FullName);
123 }
124
125 public void RemoveAt (int index)
126 {
127 TypeReference item = this [index];
128 Remove (item);
129 }
130
131 public void CopyTo (Array ary, int index)
132 {
133 this.BaseGetAllValues ().CopyTo (ary, index);
134 }
135
136 public new IEnumerator GetEnumerator ()
137 {
138 return this.BaseGetAllValues ().GetEnumerator ();
139 }
140
141 public void Accept (IReflectionVisitor visitor)
142 {
143 visitor.VisitExternTypeCollection (this);
144 }
145
146 #if CF_1_0 || CF_2_0
147 internal object [] BaseGetAllValues ()
148 {
149 object [] values = new object [this.Count];
150 for (int i=0; i < values.Length; ++i) {
151 values [i] = this.BaseGet (i);
152 }
153 return values;
154 }
155 #endif
156
157 void Check (object value)
158 {
159 if (!(value is TypeReference))
160 throw new ArgumentException ();
161 }
162
163 int IList.Add (object value)
164 {
165 Check (value);
166 Add (value as TypeReference);
167 return 0;
168 }
169
170 bool IList.Contains (object value)
171 {
172 Check (value);
173 return Contains (value as TypeReference);
174 }
175
176 int IList.IndexOf (object value)
177 {
178 throw new NotSupportedException ();
179 }
180
181 void IList.Insert (int index, object value)
182 {
183 throw new NotSupportedException ();
184 }
185
186 void IList.Remove (object value)
187 {
188 Check (value);
189 Remove (value as TypeReference);
190 }
191 }
192 }