do not check order sequence if option /order was not used
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
1 //
2 // System.Reflection.Emit.GenericTypeParameterBuilder
3 //
4 // Martin Baulig (martin@ximian.com)
5 //
6 // (C) 2004 Novell, Inc.
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Collections;
35 using System.Runtime.CompilerServices;
36 using System.Runtime.InteropServices;
37 using System.Globalization;
38 using System.Runtime.Serialization;
39
40 namespace System.Reflection.Emit
41 {
42         [ComVisible (true)]
43         [StructLayout (LayoutKind.Sequential)]
44         public sealed class GenericTypeParameterBuilder : Type
45         {
46         #region Sync with reflection.h
47                 private TypeBuilder tbuilder;
48                 private MethodBuilder mbuilder;
49                 private string name;
50                 private int index;
51                 private Type base_type;
52 #pragma warning disable 414
53                 private Type[] iface_constraints;
54                 private CustomAttributeBuilder[] cattrs;
55                 private GenericParameterAttributes attrs;
56 #pragma warning restore
57         #endregion
58
59                 public void SetBaseTypeConstraint (Type baseTypeConstraint)
60                 {
61                         this.base_type = baseTypeConstraint ?? typeof (object);
62                 }
63
64                 [ComVisible (true)]
65                 public void SetInterfaceConstraints (params Type[] interfaceConstraints)
66                 {
67                         this.iface_constraints = interfaceConstraints;
68                 }
69
70                 public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
71                 {
72                         this.attrs = genericParameterAttributes;
73                 }
74
75                 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
76                                                       MethodBuilder mbuilder,
77                                                       string name, int index)
78                 {
79                         this.tbuilder = tbuilder;
80                         this.mbuilder = mbuilder;
81                         this.name = name;
82                         this.index = index;
83
84                         initialize ();
85                 }
86
87                 internal override Type InternalResolve ()
88                 {
89                         return tbuilder.InternalResolve ().GetGenericArguments () [index]; 
90                 }
91
92                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
93                 private extern void initialize ();
94
95                 [ComVisible (true)]
96                 public override bool IsSubclassOf (Type c)
97                 {
98                         throw not_supported ();
99                 }
100
101                 protected override TypeAttributes GetAttributeFlagsImpl ()
102                 {
103 #if NET_4_0
104                         return TypeAttributes.Public;
105 #else
106                         throw not_supported ();
107 #endif
108                 }
109
110                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
111                                                                        Binder binder,
112                                                                        CallingConventions callConvention,
113                                                                        Type[] types,
114                                                                        ParameterModifier[] modifiers)
115                 {
116                         throw not_supported ();
117                 }
118
119                 [ComVisible (true)]
120                 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
121                 {
122                         throw not_supported ();
123                 }
124
125                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
126                 {
127                         throw not_supported ();
128                 }
129
130                 public override EventInfo[] GetEvents ()
131                 {
132                         throw not_supported ();
133                 }
134
135                 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
136                 {
137                         throw not_supported ();
138                 }
139
140                 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
141                 {
142                         throw not_supported ();
143                 }
144
145                 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
146                 {
147                         throw not_supported ();
148                 }
149                 
150                 public override Type GetInterface (string name, bool ignoreCase)
151                 {
152                         throw not_supported ();
153                 }
154
155                 public override Type[] GetInterfaces ()
156                 {
157                         throw not_supported ();
158                 }
159                 
160                 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
161                 {
162                         throw not_supported ();
163                 }
164
165                 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
166                 {
167                         throw not_supported ();
168                 }
169
170                 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
171                 {
172                         throw not_supported ();
173                 }
174
175                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
176                                                              Binder binder,
177                                                              CallingConventions callConvention,
178                                                              Type[] types, ParameterModifier[] modifiers)
179                 {
180                         throw not_supported ();
181                 }
182
183                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
184                 {
185                         throw not_supported ();
186                 }
187
188                 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
189                 {
190                         throw not_supported ();
191                 }
192
193                 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
194                 {
195                         throw not_supported ();
196                 }
197
198                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
199                                                                  Binder binder, Type returnType,
200                                                                  Type[] types,
201                                                                  ParameterModifier[] modifiers)
202                 {
203                         throw not_supported ();
204                 }
205
206                 protected override bool HasElementTypeImpl ()
207                 {
208                         return false;
209                 }
210
211                 public override bool IsAssignableFrom (Type c)
212                 {
213                         throw not_supported ();
214                 }
215
216                 public override bool IsInstanceOfType (object o)
217                 {
218                         throw not_supported ();
219                 }
220
221                 protected override bool IsArrayImpl ()
222                 {
223                         return false;
224                 }
225
226                 protected override bool IsByRefImpl ()
227                 {
228                         return false;
229                 }
230
231                 protected override bool IsCOMObjectImpl ()
232                 {
233                         return false;
234                 }
235
236                 protected override bool IsPointerImpl ()
237                 {
238                         return false;
239                 }
240
241                 protected override bool IsPrimitiveImpl ()
242                 {
243                         return false;
244                 }
245
246                 protected override bool IsValueTypeImpl ()
247                 {
248                         return base_type != null ? base_type.IsValueType : false;
249                 }
250                 
251                 public override object InvokeMember (string name, BindingFlags invokeAttr,
252                                                      Binder binder, object target, object[] args,
253                                                      ParameterModifier[] modifiers,
254                                                      CultureInfo culture, string[] namedParameters)
255                 {
256                         throw not_supported ();
257                 }
258
259                 public override Type GetElementType ()
260                 {
261                         throw not_supported ();
262                 }
263
264                 public override Type UnderlyingSystemType {
265                         get {
266                                 return this;
267                         }
268                 }
269
270                 public override Assembly Assembly {
271                         get { return tbuilder.Assembly; }
272                 }
273
274                 public override string AssemblyQualifiedName {
275                         get { return null; }
276                 }
277
278                 public override Type BaseType {
279                         get { return base_type; }
280                 }
281
282                 public override string FullName {
283                         get { return null; }
284                 }
285
286                 public override Guid GUID {
287                         get { throw not_supported (); }
288                 }
289
290                 public override bool IsDefined (Type attributeType, bool inherit)
291                 {
292                         throw not_supported ();
293                 }
294
295                 public override object[] GetCustomAttributes (bool inherit)
296                 {
297                         throw not_supported ();
298                 }
299
300                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
301                 {
302                         throw not_supported ();
303                 }
304
305                 [ComVisible (true)]
306                 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
307                 {
308                         throw not_supported ();
309                 }
310
311                 public override string Name {
312                         get { return name; }
313                 }
314
315                 public override string Namespace {
316                         get { return null; }
317                 }
318
319                 public override Module Module {
320                         get { return tbuilder.Module; }
321                 }
322
323                 public override Type DeclaringType {
324                         get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
325                 }
326
327                 public override Type ReflectedType {
328                         get { return DeclaringType; }
329                 }
330
331                 public override RuntimeTypeHandle TypeHandle {
332                         get { throw not_supported (); }
333                 }
334
335                 public override Type[] GetGenericArguments ()
336                 {
337                         throw new InvalidOperationException ();
338                 }
339
340                 public override Type GetGenericTypeDefinition ()
341                 {
342                         throw new InvalidOperationException ();
343                 }
344
345                 public override bool ContainsGenericParameters {
346                         get { return true; }
347                 }
348
349                 public override bool IsGenericParameter {
350                         get { return true; }
351                 }
352
353                 public override bool IsGenericType {
354                         get { return false; }
355                 }
356
357                 public override bool IsGenericTypeDefinition {
358                         get { return false; }
359                 }
360
361                 public override GenericParameterAttributes GenericParameterAttributes {
362                         get {
363                                 throw new NotSupportedException ();
364                         }
365                 }
366
367                 public override int GenericParameterPosition {
368                         get { return index; }
369                 }
370
371                 public override Type[] GetGenericParameterConstraints ()
372                 {
373                         throw new InvalidOperationException ();
374                 }
375
376                 public override MethodBase DeclaringMethod {
377                         get { return mbuilder; }
378                 }
379
380                 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
381                 {
382                         if (customBuilder == null)
383                                 throw new ArgumentNullException ("customBuilder");
384
385                         if (cattrs != null) {
386                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
387                                 cattrs.CopyTo (new_array, 0);
388                                 new_array [cattrs.Length] = customBuilder;
389                                 cattrs = new_array;
390                         } else {
391                                 cattrs = new CustomAttributeBuilder [1];
392                                 cattrs [0] = customBuilder;
393                         }
394                 }
395
396                 [MonoTODO ("unverified implementation")]
397                 public void SetCustomAttribute (ConstructorInfo con, byte [] binaryAttribute)
398                 {
399                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
400                 }
401
402                 private Exception not_supported ()
403                 {
404                         return new NotSupportedException ();
405                 }
406
407                 public override string ToString ()
408                 {
409                         return name;
410                 }
411
412                 [MonoTODO]
413                 public override bool Equals (object o)
414                 {
415                         return base.Equals (o);
416                 }
417
418                 [MonoTODO]
419                 public override int GetHashCode ()
420                 {
421                         return base.GetHashCode ();
422                 }
423
424                 public override Type MakeArrayType ()
425                 {
426                         return  new ArrayType (this, 0);
427                 }
428
429                 public override Type MakeArrayType (int rank)
430                 {
431                         if (rank < 1)
432                                 throw new IndexOutOfRangeException ();
433                         return new ArrayType (this, rank);
434                 }
435
436                 public override Type MakeByRefType ()
437                 {
438                         return new ByRefType (this);
439                 }
440
441                 [MonoTODO]
442                 public override Type MakeGenericType (params Type [] typeArguments)
443                 {
444                         return base.MakeGenericType (typeArguments);
445                 }
446
447                 public override Type MakePointerType ()
448                 {
449                         return new PointerType (this);
450                 }
451
452                 internal override bool IsUserType {
453                         get {
454                                 return false;
455                         }
456                 }
457         }
458 }