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