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