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