System.Reflection's turn to be de-ifdefified
[mono.git] / mcs / class / corlib / System.Reflection / MonoGenericClass.cs
1 //
2 // System.Reflection.MonoGenericClass
3 //
4 // Sean MacIsaac (macisaac@ximian.com)
5 // Paolo Molaro (lupus@ximian.com)
6 // Patrik Torstensson (patrik.torstensson@labs2.com)
7 //
8 // (C) 2001 Ximian, Inc.
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System.Reflection;
35 using System.Reflection.Emit;
36 using System.Collections;
37 using System.Runtime.CompilerServices;
38 using System.Globalization;
39 using System.Runtime.Serialization;
40 using System.Text;
41
42 namespace System.Reflection
43 {
44         /*
45          * MonoGenericClass represents an instantiation of a generic TypeBuilder. MS
46          * calls this class TypeBuilderInstantiation (a much better name). MS returns 
47          * NotImplementedException for many of the methods but we can't do that as gmcs
48          * depends on them.
49          */
50         internal class MonoGenericClass : MonoType
51         {
52                 #region Keep in sync with object-internals.h
53 #pragma warning disable 649
54                 internal TypeBuilder generic_type;
55                 Type[] type_arguments;
56                 bool initialized;
57 #pragma warning restore 649
58                 #endregion
59
60                 Hashtable fields, ctors, methods;
61                 int event_count;
62
63                 internal MonoGenericClass ()
64                         : base (null)
65                 {
66                         // this should not be used
67                         throw new InvalidOperationException ();
68                 }
69
70                 internal MonoGenericClass (TypeBuilder tb, Type[] args) : base (null)
71                 {
72                         this.generic_type = tb;
73                         this.type_arguments = args;
74                 }
75
76                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
77                 extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
78
79                 private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
80                 BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
81
82                 void initialize ()
83                 {
84                         if (initialized)
85                                 return;
86
87                         MonoGenericClass parent = GetParentType () as MonoGenericClass;
88                         if (parent != null)
89                                 parent.initialize ();
90                         EventInfo[] events = generic_type.GetEvents_internal (flags);
91                         event_count = events.Length;
92                                 
93                         initialize (generic_type.GetMethods (flags),
94                                                 generic_type.GetConstructorsInternal (flags),
95                                                 generic_type.GetFields (flags),
96                                                 generic_type.GetProperties (flags),
97                                                 events);
98
99                         initialized = true;
100                 }
101
102                 Type GetParentType ()
103                 {
104                         return InflateType (generic_type.BaseType);             
105                 }
106
107                 internal Type InflateType (Type type)
108                 {
109                         return InflateType (type, null);
110                 }
111
112                 internal Type InflateType (Type type, Type[] method_args)
113                 {
114                         if (type == null)
115                                 return null;
116                         if (!type.IsGenericParameter && !type.ContainsGenericParameters)
117                                 return type;
118                         if (type.IsGenericParameter) {
119                                 if (type.DeclaringMethod == null)
120                                         return type_arguments [type.GenericParameterPosition];
121                                 if (method_args != null)
122                                         return method_args [type.GenericParameterPosition];
123                                 return type;
124                         }
125                         if (type.IsPointer)
126                                 return InflateType (type.GetElementType (), method_args).MakePointerType ();
127                         if (type.IsByRef)
128                                 return InflateType (type.GetElementType (), method_args).MakeByRefType ();
129                         if (type.IsArray) {
130                                 if (type.GetArrayRank () > 1)
131                                         return InflateType (type.GetElementType (), method_args).MakeArrayType (type.GetArrayRank ());
132 #if BOOTSTRAP_NET_2_0
133                                 if (type.ToString ().EndsWith ("[*]"))
134 #else
135                                 if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
136 #endif
137                                         return InflateType (type.GetElementType (), method_args).MakeArrayType (1);
138                                 return InflateType (type.GetElementType (), method_args).MakeArrayType ();
139                         }
140
141                         Type[] args = type.GetGenericArguments ();
142                         for (int i = 0; i < args.Length; ++i)
143                                 args [i] = InflateType (args [i], method_args);
144
145                         Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
146                         return gtd.MakeGenericType (args);
147                 }
148                 
149                 public override Type BaseType {
150                         get {
151                                 Type parent = GetParentType ();
152                                 return parent != null ? parent : generic_type.BaseType;
153                         }
154                 }
155
156                 Type[] GetInterfacesInternal ()
157                 {
158                         if (generic_type.interfaces == null)
159                                 return new Type [0];
160                         Type[] res = new Type [generic_type.interfaces.Length];
161                         for (int i = 0; i < res.Length; ++i)
162                                 res [i] = InflateType (generic_type.interfaces [i]);
163                         return res;
164                 }
165
166                 public override Type[] GetInterfaces ()
167                 {
168                         if (!generic_type.IsCompilerContext)
169                                 throw new NotSupportedException ();
170                         return GetInterfacesInternal ();
171                 }
172
173                 protected override bool IsValueTypeImpl ()
174                 {
175                         return generic_type.IsValueType;
176                 }
177
178                 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
179                 {
180                         initialize ();
181
182                         if (!(fromNoninstanciated is MethodBuilder))
183                                 throw new InvalidOperationException ("Inflating non MethodBuilder objects is not supported: " + fromNoninstanciated.GetType ());
184         
185                         MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
186                         if (methods == null)
187                                 methods = new Hashtable ();
188                         if (!methods.ContainsKey (mb))
189                                 methods [mb] = new MethodOnTypeBuilderInst (this, mb);
190                         return (MethodInfo)methods [mb];
191                 }
192
193                 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
194                 {
195                         initialize ();
196
197                         if (!(fromNoninstanciated is ConstructorBuilder))
198                                 throw new InvalidOperationException ("Inflating non ConstructorBuilder objects is not supported: " + fromNoninstanciated.GetType ());
199
200                         ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
201                         if (ctors == null)
202                                 ctors = new Hashtable ();
203                         if (!ctors.ContainsKey (cb))
204                                 ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
205                         return (ConstructorInfo)ctors [cb];
206                 }
207
208                 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
209                 {
210                         initialize ();
211
212                         if (!(fromNoninstanciated is FieldBuilder))
213                                 throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());
214
215                         FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
216                         if (fields == null)
217                                 fields = new Hashtable ();
218                         if (!fields.ContainsKey (fb))
219                                 fields [fb] = new FieldOnTypeBuilderInst (this, fb);
220                         return (FieldInfo)fields [fb];
221                 }
222                 
223                 public override MethodInfo[] GetMethods (BindingFlags bf)
224                 {
225                         if (!generic_type.IsCompilerContext)
226                                 throw new NotSupportedException ();
227
228                         ArrayList l = new ArrayList ();
229
230                         //
231                         // Walk up our class hierarchy and retrieve methods from our
232                         // parent classes.
233                         //
234
235                         Type current_type = this;
236                         do {
237                                 MonoGenericClass gi = current_type as MonoGenericClass;
238                                 if (gi != null)
239                                         l.AddRange (gi.GetMethodsInternal (bf, this));
240                                 else if (current_type is TypeBuilder)
241                                         l.AddRange (current_type.GetMethods (bf));
242                                 else {
243                                         // If we encounter a `MonoType', its
244                                         // GetMethodsByName() will return all the methods
245                                         // from its parent type(s), so we can stop here.
246                                         MonoType mt = (MonoType) current_type;
247                                         l.AddRange (mt.GetMethodsByName (null, bf, false, this));
248                                         break;
249                                 }
250
251                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
252                                         break;
253                                 current_type = current_type.BaseType;
254                         } while (current_type != null);
255
256                         MethodInfo[] result = new MethodInfo [l.Count];
257                         l.CopyTo (result);
258                         return result;
259                 }
260
261                 MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
262                 {
263                         if (generic_type.num_methods == 0)
264                                 return new MethodInfo [0];
265
266                         ArrayList l = new ArrayList ();
267                         bool match;
268                         MethodAttributes mattrs;
269                         MethodInfo accessor;
270
271                         initialize ();
272
273                         for (int i = 0; i < generic_type.num_methods; ++i) {
274                                 MethodInfo c = generic_type.methods [i];
275
276                                 match = false;
277                                 mattrs = c.Attributes;
278                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
279                                         if ((bf & BindingFlags.Public) != 0)
280                                                 match = true;
281                                 } else {
282                                         if ((bf & BindingFlags.NonPublic) != 0)
283                                                 match = true;
284                                 }
285                                 if (!match)
286                                         continue;
287                                 match = false;
288                                 if ((mattrs & MethodAttributes.Static) != 0) {
289                                         if ((bf & BindingFlags.Static) != 0)
290                                                 match = true;
291                                 } else {
292                                         if ((bf & BindingFlags.Instance) != 0)
293                                                 match = true;
294                                 }
295                                 if (!match)
296                                         continue;
297                                 c = TypeBuilder.GetMethod (this, c);
298                                 l.Add (c);
299                         }
300
301                         MethodInfo[] result = new MethodInfo [l.Count];
302                         l.CopyTo (result);
303                         return result;
304                 }
305
306                 public override ConstructorInfo[] GetConstructors (BindingFlags bf)
307                 {
308                         if (!generic_type.IsCompilerContext)
309                                 throw new NotSupportedException ();
310
311                         ArrayList l = new ArrayList ();
312
313                         Type current_type = this;
314                         do {
315                                 MonoGenericClass gi = current_type as MonoGenericClass;
316                                 if (gi != null)
317                                         l.AddRange (gi.GetConstructorsInternal (bf, this));
318                                 else if (current_type is TypeBuilder)
319                                         l.AddRange (current_type.GetConstructors (bf));
320                                 else {
321                                         MonoType mt = (MonoType) current_type;
322                                         l.AddRange (mt.GetConstructors_internal (bf, this));
323                                         break;
324                                 }
325
326                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
327                                         break;
328                                 current_type = current_type.BaseType;
329                         } while (current_type != null);
330
331                         ConstructorInfo[] result = new ConstructorInfo [l.Count];
332                         l.CopyTo (result);
333                         return result;
334                 }
335
336                 ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
337                 {
338                         if (generic_type.ctors == null)
339                                 return new ConstructorInfo [0];
340
341                         ArrayList l = new ArrayList ();
342                         bool match;
343                         MethodAttributes mattrs;
344
345                         initialize ();
346
347                         for (int i = 0; i < generic_type.ctors.Length; i++) {
348                                 ConstructorInfo c = generic_type.ctors [i];
349
350                                 match = false;
351                                 mattrs = c.Attributes;
352                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
353                                         if ((bf & BindingFlags.Public) != 0)
354                                                 match = true;
355                                 } else {
356                                         if ((bf & BindingFlags.NonPublic) != 0)
357                                                 match = true;
358                                 }
359                                 if (!match)
360                                         continue;
361                                 match = false;
362                                 if ((mattrs & MethodAttributes.Static) != 0) {
363                                         if ((bf & BindingFlags.Static) != 0)
364                                                 match = true;
365                                 } else {
366                                         if ((bf & BindingFlags.Instance) != 0)
367                                                 match = true;
368                                 }
369                                 if (!match)
370                                         continue;
371                                 l.Add (TypeBuilder.GetConstructor (this, c));
372                         }
373
374                         ConstructorInfo[] result = new ConstructorInfo [l.Count];
375                         l.CopyTo (result);
376                         return result;
377                 }
378
379                 public override FieldInfo[] GetFields (BindingFlags bf)
380                 {
381                         if (!generic_type.IsCompilerContext)
382                                 throw new NotSupportedException ();
383
384                         ArrayList l = new ArrayList ();
385
386                         Type current_type = this;
387                         do {
388                                 MonoGenericClass gi = current_type as MonoGenericClass;
389                                 if (gi != null)
390                                         l.AddRange (gi.GetFieldsInternal (bf, this));
391                                 else if (current_type is TypeBuilder)
392                                         l.AddRange (current_type.GetFields (bf));
393                                 else {
394                                         MonoType mt = (MonoType) current_type;
395                                         l.AddRange (mt.GetFields_internal (bf, this));
396                                         break;
397                                 }
398
399                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
400                                         break;
401                                 current_type = current_type.BaseType;
402                         } while (current_type != null);
403
404                         FieldInfo[] result = new FieldInfo [l.Count];
405                         l.CopyTo (result);
406                         return result;
407                 }
408
409                 FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
410                 {
411                         if (generic_type.num_fields == 0)
412                                 return new FieldInfo [0];
413
414                         ArrayList l = new ArrayList ();
415                         bool match;
416                         FieldAttributes fattrs;
417
418                         initialize ();
419
420                         for (int i = 0; i < generic_type.num_fields; i++) {
421                                 FieldInfo c = generic_type.fields [i];
422
423                                 match = false;
424                                 fattrs = c.Attributes;
425                                 if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
426                                         if ((bf & BindingFlags.Public) != 0)
427                                                 match = true;
428                                 } else {
429                                         if ((bf & BindingFlags.NonPublic) != 0)
430                                                 match = true;
431                                 }
432                                 if (!match)
433                                         continue;
434                                 match = false;
435                                 if ((fattrs & FieldAttributes.Static) != 0) {
436                                         if ((bf & BindingFlags.Static) != 0)
437                                                 match = true;
438                                 } else {
439                                         if ((bf & BindingFlags.Instance) != 0)
440                                                 match = true;
441                                 }
442                                 if (!match)
443                                         continue;
444                                 l.Add (TypeBuilder.GetField (this, c));
445                         }
446
447                         FieldInfo[] result = new FieldInfo [l.Count];
448                         l.CopyTo (result);
449                         return result;
450                 }
451
452                 public override PropertyInfo[] GetProperties (BindingFlags bf)
453                 {
454                         if (!generic_type.IsCompilerContext)
455                                 throw new NotSupportedException ();
456
457                         ArrayList l = new ArrayList ();
458
459                         Type current_type = this;
460                         do {
461                                 MonoGenericClass gi = current_type as MonoGenericClass;
462                                 if (gi != null)
463                                         l.AddRange (gi.GetPropertiesInternal (bf, this));
464                                 else if (current_type is TypeBuilder)
465                                         l.AddRange (current_type.GetProperties (bf));
466                                 else {
467                                         MonoType mt = (MonoType) current_type;
468                                         l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
469                                         break;
470                                 }
471
472                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
473                                         break;
474                                 current_type = current_type.BaseType;
475                         } while (current_type != null);
476
477                         PropertyInfo[] result = new PropertyInfo [l.Count];
478                         l.CopyTo (result);
479                         return result;
480                 }
481
482                 PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
483                 {
484                         if (generic_type.properties == null)
485                                 return new PropertyInfo [0];
486
487                         ArrayList l = new ArrayList ();
488                         bool match;
489                         MethodAttributes mattrs;
490                         MethodInfo accessor;
491
492                         initialize ();
493
494                         foreach (PropertyInfo pinfo in generic_type.properties) {
495                                 match = false;
496                                 accessor = pinfo.GetGetMethod (true);
497                                 if (accessor == null)
498                                         accessor = pinfo.GetSetMethod (true);
499                                 if (accessor == null)
500                                         continue;
501                                 mattrs = accessor.Attributes;
502                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
503                                         if ((bf & BindingFlags.Public) != 0)
504                                                 match = true;
505                                 } else {
506                                         if ((bf & BindingFlags.NonPublic) != 0)
507                                                 match = true;
508                                 }
509                                 if (!match)
510                                         continue;
511                                 match = false;
512                                 if ((mattrs & MethodAttributes.Static) != 0) {
513                                         if ((bf & BindingFlags.Static) != 0)
514                                                 match = true;
515                                 } else {
516                                         if ((bf & BindingFlags.Instance) != 0)
517                                                 match = true;
518                                 }
519                                 if (!match)
520                                         continue;
521                                 l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
522                         }
523                         PropertyInfo[] result = new PropertyInfo [l.Count];
524                         l.CopyTo (result);
525                         return result;
526                 }
527
528                 public override EventInfo[] GetEvents (BindingFlags bf)
529                 {
530                         if (!generic_type.IsCompilerContext)
531                                 throw new NotSupportedException ();
532
533                         ArrayList l = new ArrayList ();
534
535                         Type current_type = this;
536                         do {
537                                 MonoGenericClass gi = current_type as MonoGenericClass;
538                                 if (gi != null)
539                                         l.AddRange (gi.GetEventsInternal (bf, this));
540                                 else if (current_type is TypeBuilder)
541                                         l.AddRange (current_type.GetEvents (bf));
542                                 else {
543                                         MonoType mt = (MonoType) current_type;
544                                         l.AddRange (mt.GetEvents (bf));
545                                         break;
546                                 }
547
548                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
549                                         break;
550                                 current_type = current_type.BaseType;
551                         } while (current_type != null);
552
553                         EventInfo[] result = new EventInfo [l.Count];
554                         l.CopyTo (result);
555                         return result;
556                 }
557         
558                 EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
559                         if (generic_type.events == null)
560                                 return new EventInfo [0];
561
562                         initialize ();
563
564                         ArrayList l = new ArrayList ();
565                         bool match;
566                         MethodAttributes mattrs;
567                         MethodInfo accessor;
568
569                         for (int i = 0; i < event_count; ++i) {
570                                 EventBuilder ev = generic_type.events [i];
571
572                                 match = false;
573                                 accessor = ev.add_method;
574                                 if (accessor == null)
575                                         accessor = ev.remove_method;
576                                 if (accessor == null)
577                                         continue;
578                                 mattrs = accessor.Attributes;
579                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
580                                         if ((bf & BindingFlags.Public) != 0)
581                                                 match = true;
582                                 } else {
583                                         if ((bf & BindingFlags.NonPublic) != 0)
584                                                 match = true;
585                                 }
586                                 if (!match)
587                                         continue;
588                                 match = false;
589                                 if ((mattrs & MethodAttributes.Static) != 0) {
590                                         if ((bf & BindingFlags.Static) != 0)
591                                                 match = true;
592                                 } else {
593                                         if ((bf & BindingFlags.Instance) != 0)
594                                                 match = true;
595                                 }
596                                 if (!match)
597                                         continue;
598                                 l.Add (new EventOnTypeBuilderInst (this, ev));
599                         }
600                         EventInfo[] result = new EventInfo [l.Count];
601                         l.CopyTo (result);
602                         return result;
603                 }
604
605                 public override Type[] GetNestedTypes (BindingFlags bf)
606                 {
607                         return generic_type.GetNestedTypes (bf);
608                 }
609
610                 public override bool IsAssignableFrom (Type c)
611                 {
612                         if (c == this)
613                                 return true;
614
615                         Type[] interfaces = GetInterfacesInternal ();
616
617                         if (c.IsInterface) {
618                                 if (interfaces == null)
619                                         return false;
620                                 foreach (Type t in interfaces)
621                                         if (c.IsAssignableFrom (t))
622                                                 return true;
623                                 return false;
624                         }
625
626                         Type parent = GetParentType ();
627                         if (parent == null)
628                                 return c == typeof (object);
629                         else
630                                 return c.IsAssignableFrom (parent);
631                 }
632
633                 public override Type UnderlyingSystemType {
634                         get { return this; }
635                 }
636
637                 public override string Name {
638                         get { return generic_type.Name; }
639                 }
640
641                 public override string Namespace {
642                         get { return generic_type.Namespace; }
643                 }
644
645                 public override string FullName {
646                         get { return format_name (true, false); }
647                 }
648
649                 public override string AssemblyQualifiedName {
650                         get { return format_name (true, true); }
651                 }
652
653                 public override Guid GUID {
654                         get { throw new NotSupportedException (); }
655                 }
656
657                 string format_name (bool full_name, bool assembly_qualified)
658                 {
659                         StringBuilder sb = new StringBuilder (generic_type.FullName);
660                         bool compiler_ctx = generic_type.IsCompilerContext;
661
662                         sb.Append ("[");
663                         for (int i = 0; i < type_arguments.Length; ++i) {
664                                 if (i > 0)
665                                         sb.Append (",");
666                                 
667                                 string name = full_name ? type_arguments [i].AssemblyQualifiedName : type_arguments [i].ToString ();
668                                 if (name == null) {
669                                         if (compiler_ctx && type_arguments [i].IsGenericParameter)
670                                                 name = type_arguments [i].Name;
671                                         else
672                                                 return null;
673                                 }
674                                 if (full_name)
675                                         sb.Append ("[");
676                                 sb.Append (name);
677                                 if (full_name)
678                                         sb.Append ("]");
679                         }
680                         sb.Append ("]");
681                         if (assembly_qualified) {
682                                 sb.Append (", ");
683                                 sb.Append (generic_type.Assembly.FullName);
684                         }
685                         return sb.ToString ();
686                 }
687
688                 public override string ToString ()
689                 {
690                         return format_name (false, false);
691                 }
692
693                 public override Type MakeArrayType ()
694                 {
695                         return new ArrayType (this, 0);
696                 }
697
698                 public override Type MakeArrayType (int rank)
699                 {
700                         if (rank < 1)
701                                 throw new IndexOutOfRangeException ();
702                         return new ArrayType (this, rank);
703                 }
704
705                 public override Type MakeByRefType ()
706                 {
707                         return new ByRefType (this);
708                 }
709
710                 public override Type MakePointerType ()
711                 {
712                         return new PointerType (this);
713                 }
714
715                 /*public override Type GetElementType ()
716                 {
717                         throw new NotSupportedException ();
718                 }*/
719
720                 protected override bool IsCOMObjectImpl ()
721                 {
722                         return false;
723                 }
724
725                 protected override bool IsPrimitiveImpl ()
726                 {
727                         return false;
728                 }
729
730                 /*
731                 protected override bool IsArrayImpl ()
732                 {
733                         return false;
734                 }
735
736                 protected override bool IsByRefImpl ()
737                 {
738                         return false;
739                 }
740
741                 protected override bool IsPointerImpl ()
742                 {
743                         return false;
744                 }*/
745
746                 protected override TypeAttributes GetAttributeFlagsImpl ()
747                 {
748                         return generic_type.Attributes; 
749                 }
750
751                 //stuff that throws
752                 public override Type GetInterface (string name, bool ignoreCase)
753                 {
754                         throw new NotSupportedException ();
755                 }
756
757                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
758                 {
759                         if (!generic_type.IsCompilerContext)
760                                 throw new NotSupportedException ();
761                         foreach (var evt in GetEvents (bindingAttr)) {
762                                 if (evt.Name == name)
763                                         return evt;
764                         }
765                         return null;
766                 }
767
768                 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
769                 {
770                         throw new NotSupportedException ();
771                 }
772
773                 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
774                 {
775                         throw new NotSupportedException ();
776                 }
777
778                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
779                 {
780                         throw new NotSupportedException ();
781                 }
782
783                 public override object InvokeMember (string name, BindingFlags invokeAttr,
784                                                      Binder binder, object target, object[] args,
785                                                      ParameterModifier[] modifiers,
786                                                      CultureInfo culture, string[] namedParameters)
787                 {
788                         throw new NotSupportedException ();
789                 }
790
791                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
792                                                              CallingConventions callConvention, Type[] types,
793                                                              ParameterModifier[] modifiers)
794                 {
795                         throw new NotSupportedException ();
796                 }
797
798                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
799                                                                  Type returnType, Type[] types, ParameterModifier[] modifiers)
800                 {
801                         throw new NotSupportedException ();
802                 }
803
804                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
805                                                                        Binder binder,
806                                                                        CallingConventions callConvention,
807                                                                        Type[] types,
808                                                                        ParameterModifier[] modifiers)
809                 {
810                         throw new NotSupportedException ();
811                 }
812
813                 //MemberInfo
814                 public override bool IsDefined (Type attributeType, bool inherit)
815                 {
816                         throw new NotSupportedException ();
817                 }
818
819                 public override object [] GetCustomAttributes (bool inherit)
820                 {
821                         throw new NotSupportedException ();
822                 }
823
824                 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
825                 {
826                         throw new NotSupportedException ();
827                 }
828         }
829 }
830