2 // TypeReferenceCollection.cs
5 // Jb Evain (jbevain@gmail.com)
7 // Generated by /CodeGen/cecil-gen.rb do not edit
8 // Fri Mar 30 18:43:56 +0200 2007
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
32 namespace Mono.Cecil {
35 using System.Collections;
36 using System.Collections.Specialized;
40 using Hcp = Mono.Cecil.HashCodeProvider;
41 using Cmp = System.Collections.Comparer;
43 internal sealed class TypeReferenceCollection : NameObjectCollectionBase, IList, IReflectionVisitable {
45 ModuleDefinition m_container;
47 public TypeReference this [int index] {
48 get { return this.BaseGet (index) as TypeReference; }
49 set { this.BaseSet (index, value); }
52 public TypeReference this [string fullName] {
53 get { return this.BaseGet (fullName) as TypeReference; }
54 set { this.BaseSet (fullName, value); }
57 public ModuleDefinition Container {
58 get { return m_container; }
61 public bool IsSynchronized {
65 public object SyncRoot {
69 bool IList.IsReadOnly {
73 bool IList.IsFixedSize {
77 object IList.this [int index] {
78 get { return BaseGet (index); }
81 BaseSet (index, value);
85 public TypeReferenceCollection (ModuleDefinition container) :
86 base (Hcp.Instance, Cmp.Default)
88 m_container = container;
91 public void Add (TypeReference value)
94 throw new ArgumentNullException ("value");
98 this.BaseAdd (value.FullName, value);
103 foreach (TypeReference item in this)
109 public bool Contains (TypeReference value)
111 return Contains (value.FullName);
114 public bool Contains (string fullName)
116 return this.BaseGet (fullName) != null;
119 public int IndexOf (TypeReference value)
121 string [] keys = this.BaseGetAllKeys ();
122 return Array.IndexOf (keys, value.FullName, 0, keys.Length);
125 public void Remove (TypeReference value)
127 this.BaseRemove (value.FullName);
132 public void RemoveAt (int index)
134 TypeReference item = this [index];
140 public void CopyTo (Array ary, int index)
142 this.BaseGetAllValues ().CopyTo (ary, index);
145 public new IEnumerator GetEnumerator ()
147 return this.BaseGetAllValues ().GetEnumerator ();
150 public void Accept (IReflectionVisitor visitor)
152 visitor.VisitTypeReferenceCollection (this);
156 internal object [] BaseGetAllValues ()
158 object [] values = new object [this.Count];
159 for (int i=0; i < values.Length; ++i) {
160 values [i] = this.BaseGet (i);
166 void Check (object value)
168 if (!(value is TypeReference))
169 throw new ArgumentException ();
172 int IList.Add (object value)
175 Add (value as TypeReference);
179 bool IList.Contains (object value)
182 return Contains (value as TypeReference);
185 int IList.IndexOf (object value)
187 throw new NotSupportedException ();
190 void IList.Insert (int index, object value)
192 throw new NotSupportedException ();
195 void IList.Remove (object value)
198 Remove (value as TypeReference);
201 void Detach (TypeReference type)
206 void Attach (TypeReference type)
208 if (type.Module != null)
209 throw new ReflectionException ("Type is already attached, clone it instead");
211 type.Module = m_container;