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