2009-12-04 Rodrigo Kumpera <rkumpera@novell.com>
[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, type_arguments, null);
110                 }
111
112                 internal Type InflateType (Type type, Type[] method_args)
113                 {
114                         return InflateType (type, type_arguments, method_args);
115                 }
116
117                 internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
118                 {
119                         if (type == null)
120                                 return null;
121                         if (!type.IsGenericParameter && !type.ContainsGenericParameters)
122                                 return type;
123                         if (type.IsGenericParameter) {
124                                 if (type.DeclaringMethod == null)
125                                         return type_args == null ? type : type_args [type.GenericParameterPosition];
126                                 return method_args == null ? type : method_args [type.GenericParameterPosition];
127                         }
128                         if (type.IsPointer)
129                                 return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
130                         if (type.IsByRef)
131                                 return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
132                         if (type.IsArray) {
133                                 if (type.GetArrayRank () > 1)
134                                         return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
135 #if BOOTSTRAP_NET_2_0
136                                 if (type.ToString ().EndsWith ("[*]"))
137 #else
138                                 if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
139 #endif
140                                         return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
141                                 return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
142                         }
143
144                         Type[] args = type.GetGenericArguments ();
145                         for (int i = 0; i < args.Length; ++i)
146                                 args [i] = InflateType (args [i], type_args, method_args);
147
148                         Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
149                         return gtd.MakeGenericType (args);
150                 }
151                 
152                 public override Type BaseType {
153                         get {
154                                 Type parent = GetParentType ();
155                                 return parent != null ? parent : generic_type.BaseType;
156                         }
157                 }
158
159                 Type[] GetInterfacesInternal ()
160                 {
161                         if (generic_type.interfaces == null)
162                                 return new Type [0];
163                         Type[] res = new Type [generic_type.interfaces.Length];
164                         for (int i = 0; i < res.Length; ++i)
165                                 res [i] = InflateType (generic_type.interfaces [i]);
166                         return res;
167                 }
168
169                 public override Type[] GetInterfaces ()
170                 {
171                         if (!generic_type.IsCompilerContext)
172                                 throw new NotSupportedException ();
173                         return GetInterfacesInternal ();
174                 }
175
176                 protected override bool IsValueTypeImpl ()
177                 {
178                         return generic_type.IsValueType;
179                 }
180
181                 internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
182                 {
183                         initialize ();
184
185                         if (!(fromNoninstanciated is MethodBuilder))
186                                 throw new InvalidOperationException ("Inflating non MethodBuilder objects is not supported: " + fromNoninstanciated.GetType ());
187         
188                         MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
189                         if (methods == null)
190                                 methods = new Hashtable ();
191                         if (!methods.ContainsKey (mb))
192                                 methods [mb] = new MethodOnTypeBuilderInst (this, mb);
193                         return (MethodInfo)methods [mb];
194                 }
195
196                 internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
197                 {
198                         initialize ();
199
200                         if (!(fromNoninstanciated is ConstructorBuilder))
201                                 throw new InvalidOperationException ("Inflating non ConstructorBuilder objects is not supported: " + fromNoninstanciated.GetType ());
202
203                         ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
204                         if (ctors == null)
205                                 ctors = new Hashtable ();
206                         if (!ctors.ContainsKey (cb))
207                                 ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
208                         return (ConstructorInfo)ctors [cb];
209                 }
210
211                 internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
212                 {
213                         initialize ();
214
215                         if (!(fromNoninstanciated is FieldBuilder))
216                                 throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());
217
218                         FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
219                         if (fields == null)
220                                 fields = new Hashtable ();
221                         if (!fields.ContainsKey (fb))
222                                 fields [fb] = new FieldOnTypeBuilderInst (this, fb);
223                         return (FieldInfo)fields [fb];
224                 }
225                 
226                 public override MethodInfo[] GetMethods (BindingFlags bf)
227                 {
228                         if (!generic_type.IsCompilerContext)
229                                 throw new NotSupportedException ();
230
231                         ArrayList l = new ArrayList ();
232
233                         //
234                         // Walk up our class hierarchy and retrieve methods from our
235                         // parent classes.
236                         //
237
238                         Type current_type = this;
239                         do {
240                                 MonoGenericClass gi = current_type as MonoGenericClass;
241                                 if (gi != null)
242                                         l.AddRange (gi.GetMethodsInternal (bf, this));
243                                 else if (current_type is TypeBuilder)
244                                         l.AddRange (current_type.GetMethods (bf));
245                                 else {
246                                         // If we encounter a `MonoType', its
247                                         // GetMethodsByName() will return all the methods
248                                         // from its parent type(s), so we can stop here.
249                                         MonoType mt = (MonoType) current_type;
250                                         l.AddRange (mt.GetMethodsByName (null, bf, false, this));
251                                         break;
252                                 }
253
254                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
255                                         break;
256                                 current_type = current_type.BaseType;
257                         } while (current_type != null);
258
259                         MethodInfo[] result = new MethodInfo [l.Count];
260                         l.CopyTo (result);
261                         return result;
262                 }
263
264                 MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
265                 {
266                         if (generic_type.num_methods == 0)
267                                 return new MethodInfo [0];
268
269                         ArrayList l = new ArrayList ();
270                         bool match;
271                         MethodAttributes mattrs;
272
273                         initialize ();
274
275                         for (int i = 0; i < generic_type.num_methods; ++i) {
276                                 MethodInfo c = generic_type.methods [i];
277
278                                 match = false;
279                                 mattrs = c.Attributes;
280                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
281                                         if ((bf & BindingFlags.Public) != 0)
282                                                 match = true;
283                                 } else {
284                                         if ((bf & BindingFlags.NonPublic) != 0)
285                                                 match = true;
286                                 }
287                                 if (!match)
288                                         continue;
289                                 match = false;
290                                 if ((mattrs & MethodAttributes.Static) != 0) {
291                                         if ((bf & BindingFlags.Static) != 0)
292                                                 match = true;
293                                 } else {
294                                         if ((bf & BindingFlags.Instance) != 0)
295                                                 match = true;
296                                 }
297                                 if (!match)
298                                         continue;
299                                 c = TypeBuilder.GetMethod (this, c);
300                                 l.Add (c);
301                         }
302
303                         MethodInfo[] result = new MethodInfo [l.Count];
304                         l.CopyTo (result);
305                         return result;
306                 }
307
308                 public override ConstructorInfo[] GetConstructors (BindingFlags bf)
309                 {
310                         if (!generic_type.IsCompilerContext)
311                                 throw new NotSupportedException ();
312
313                         ArrayList l = new ArrayList ();
314
315                         Type current_type = this;
316                         do {
317                                 MonoGenericClass gi = current_type as MonoGenericClass;
318                                 if (gi != null)
319                                         l.AddRange (gi.GetConstructorsInternal (bf, this));
320                                 else if (current_type is TypeBuilder)
321                                         l.AddRange (current_type.GetConstructors (bf));
322                                 else {
323                                         MonoType mt = (MonoType) current_type;
324                                         l.AddRange (mt.GetConstructors_internal (bf, this));
325                                         break;
326                                 }
327
328                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
329                                         break;
330                                 current_type = current_type.BaseType;
331                         } while (current_type != null);
332
333                         ConstructorInfo[] result = new ConstructorInfo [l.Count];
334                         l.CopyTo (result);
335                         return result;
336                 }
337
338                 ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
339                 {
340                         if (generic_type.ctors == null)
341                                 return new ConstructorInfo [0];
342
343                         ArrayList l = new ArrayList ();
344                         bool match;
345                         MethodAttributes mattrs;
346
347                         initialize ();
348
349                         for (int i = 0; i < generic_type.ctors.Length; i++) {
350                                 ConstructorInfo c = generic_type.ctors [i];
351
352                                 match = false;
353                                 mattrs = c.Attributes;
354                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
355                                         if ((bf & BindingFlags.Public) != 0)
356                                                 match = true;
357                                 } else {
358                                         if ((bf & BindingFlags.NonPublic) != 0)
359                                                 match = true;
360                                 }
361                                 if (!match)
362                                         continue;
363                                 match = false;
364                                 if ((mattrs & MethodAttributes.Static) != 0) {
365                                         if ((bf & BindingFlags.Static) != 0)
366                                                 match = true;
367                                 } else {
368                                         if ((bf & BindingFlags.Instance) != 0)
369                                                 match = true;
370                                 }
371                                 if (!match)
372                                         continue;
373                                 l.Add (TypeBuilder.GetConstructor (this, c));
374                         }
375
376                         ConstructorInfo[] result = new ConstructorInfo [l.Count];
377                         l.CopyTo (result);
378                         return result;
379                 }
380
381                 public override FieldInfo[] GetFields (BindingFlags bf)
382                 {
383                         if (!generic_type.IsCompilerContext)
384                                 throw new NotSupportedException ();
385
386                         ArrayList l = new ArrayList ();
387
388                         Type current_type = this;
389                         do {
390                                 MonoGenericClass gi = current_type as MonoGenericClass;
391                                 if (gi != null)
392                                         l.AddRange (gi.GetFieldsInternal (bf, this));
393                                 else if (current_type is TypeBuilder)
394                                         l.AddRange (current_type.GetFields (bf));
395                                 else {
396                                         MonoType mt = (MonoType) current_type;
397                                         l.AddRange (mt.GetFields_internal (bf, this));
398                                         break;
399                                 }
400
401                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
402                                         break;
403                                 current_type = current_type.BaseType;
404                         } while (current_type != null);
405
406                         FieldInfo[] result = new FieldInfo [l.Count];
407                         l.CopyTo (result);
408                         return result;
409                 }
410
411                 FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
412                 {
413                         if (generic_type.num_fields == 0)
414                                 return new FieldInfo [0];
415
416                         ArrayList l = new ArrayList ();
417                         bool match;
418                         FieldAttributes fattrs;
419
420                         initialize ();
421
422                         for (int i = 0; i < generic_type.num_fields; i++) {
423                                 FieldInfo c = generic_type.fields [i];
424
425                                 match = false;
426                                 fattrs = c.Attributes;
427                                 if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
428                                         if ((bf & BindingFlags.Public) != 0)
429                                                 match = true;
430                                 } else {
431                                         if ((bf & BindingFlags.NonPublic) != 0)
432                                                 match = true;
433                                 }
434                                 if (!match)
435                                         continue;
436                                 match = false;
437                                 if ((fattrs & FieldAttributes.Static) != 0) {
438                                         if ((bf & BindingFlags.Static) != 0)
439                                                 match = true;
440                                 } else {
441                                         if ((bf & BindingFlags.Instance) != 0)
442                                                 match = true;
443                                 }
444                                 if (!match)
445                                         continue;
446                                 l.Add (TypeBuilder.GetField (this, c));
447                         }
448
449                         FieldInfo[] result = new FieldInfo [l.Count];
450                         l.CopyTo (result);
451                         return result;
452                 }
453
454                 public override PropertyInfo[] GetProperties (BindingFlags bf)
455                 {
456                         if (!generic_type.IsCompilerContext)
457                                 throw new NotSupportedException ();
458
459                         ArrayList l = new ArrayList ();
460
461                         Type current_type = this;
462                         do {
463                                 MonoGenericClass gi = current_type as MonoGenericClass;
464                                 if (gi != null)
465                                         l.AddRange (gi.GetPropertiesInternal (bf, this));
466                                 else if (current_type is TypeBuilder)
467                                         l.AddRange (current_type.GetProperties (bf));
468                                 else {
469                                         MonoType mt = (MonoType) current_type;
470                                         l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
471                                         break;
472                                 }
473
474                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
475                                         break;
476                                 current_type = current_type.BaseType;
477                         } while (current_type != null);
478
479                         PropertyInfo[] result = new PropertyInfo [l.Count];
480                         l.CopyTo (result);
481                         return result;
482                 }
483
484                 PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
485                 {
486                         if (generic_type.properties == null)
487                                 return new PropertyInfo [0];
488
489                         ArrayList l = new ArrayList ();
490                         bool match;
491                         MethodAttributes mattrs;
492                         MethodInfo accessor;
493
494                         initialize ();
495
496                         foreach (PropertyInfo pinfo in generic_type.properties) {
497                                 match = false;
498                                 accessor = pinfo.GetGetMethod (true);
499                                 if (accessor == null)
500                                         accessor = pinfo.GetSetMethod (true);
501                                 if (accessor == null)
502                                         continue;
503                                 mattrs = accessor.Attributes;
504                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
505                                         if ((bf & BindingFlags.Public) != 0)
506                                                 match = true;
507                                 } else {
508                                         if ((bf & BindingFlags.NonPublic) != 0)
509                                                 match = true;
510                                 }
511                                 if (!match)
512                                         continue;
513                                 match = false;
514                                 if ((mattrs & MethodAttributes.Static) != 0) {
515                                         if ((bf & BindingFlags.Static) != 0)
516                                                 match = true;
517                                 } else {
518                                         if ((bf & BindingFlags.Instance) != 0)
519                                                 match = true;
520                                 }
521                                 if (!match)
522                                         continue;
523                                 l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
524                         }
525                         PropertyInfo[] result = new PropertyInfo [l.Count];
526                         l.CopyTo (result);
527                         return result;
528                 }
529
530                 public override EventInfo[] GetEvents (BindingFlags bf)
531                 {
532                         if (!generic_type.IsCompilerContext)
533                                 throw new NotSupportedException ();
534
535                         ArrayList l = new ArrayList ();
536
537                         Type current_type = this;
538                         do {
539                                 MonoGenericClass gi = current_type as MonoGenericClass;
540                                 if (gi != null)
541                                         l.AddRange (gi.GetEventsInternal (bf, this));
542                                 else if (current_type is TypeBuilder)
543                                         l.AddRange (current_type.GetEvents (bf));
544                                 else {
545                                         MonoType mt = (MonoType) current_type;
546                                         l.AddRange (mt.GetEvents (bf));
547                                         break;
548                                 }
549
550                                 if ((bf & BindingFlags.DeclaredOnly) != 0)
551                                         break;
552                                 current_type = current_type.BaseType;
553                         } while (current_type != null);
554
555                         EventInfo[] result = new EventInfo [l.Count];
556                         l.CopyTo (result);
557                         return result;
558                 }
559         
560                 EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
561                         if (generic_type.events == null)
562                                 return new EventInfo [0];
563
564                         initialize ();
565
566                         ArrayList l = new ArrayList ();
567                         bool match;
568                         MethodAttributes mattrs;
569                         MethodInfo accessor;
570
571                         for (int i = 0; i < event_count; ++i) {
572                                 EventBuilder ev = generic_type.events [i];
573
574                                 match = false;
575                                 accessor = ev.add_method;
576                                 if (accessor == null)
577                                         accessor = ev.remove_method;
578                                 if (accessor == null)
579                                         continue;
580                                 mattrs = accessor.Attributes;
581                                 if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
582                                         if ((bf & BindingFlags.Public) != 0)
583                                                 match = true;
584                                 } else {
585                                         if ((bf & BindingFlags.NonPublic) != 0)
586                                                 match = true;
587                                 }
588                                 if (!match)
589                                         continue;
590                                 match = false;
591                                 if ((mattrs & MethodAttributes.Static) != 0) {
592                                         if ((bf & BindingFlags.Static) != 0)
593                                                 match = true;
594                                 } else {
595                                         if ((bf & BindingFlags.Instance) != 0)
596                                                 match = true;
597                                 }
598                                 if (!match)
599                                         continue;
600                                 l.Add (new EventOnTypeBuilderInst (this, ev));
601                         }
602                         EventInfo[] result = new EventInfo [l.Count];
603                         l.CopyTo (result);
604                         return result;
605                 }
606
607                 public override Type[] GetNestedTypes (BindingFlags bf)
608                 {
609                         return generic_type.GetNestedTypes (bf);
610                 }
611
612                 public override bool IsAssignableFrom (Type c)
613                 {
614                         if (c == this)
615                                 return true;
616
617                         Type[] interfaces = GetInterfacesInternal ();
618
619                         if (c.IsInterface) {
620                                 if (interfaces == null)
621                                         return false;
622                                 foreach (Type t in interfaces)
623                                         if (c.IsAssignableFrom (t))
624                                                 return true;
625                                 return false;
626                         }
627
628                         Type parent = GetParentType ();
629                         if (parent == null)
630                                 return c == typeof (object);
631                         else
632                                 return c.IsAssignableFrom (parent);
633                 }
634
635                 public override Type UnderlyingSystemType {
636                         get { return this; }
637                 }
638
639                 public override string Name {
640                         get { return generic_type.Name; }
641                 }
642
643                 public override string Namespace {
644                         get { return generic_type.Namespace; }
645                 }
646
647                 public override string FullName {
648                         get { return format_name (true, false); }
649                 }
650
651                 public override string AssemblyQualifiedName {
652                         get { return format_name (true, true); }
653                 }
654
655                 public override Guid GUID {
656                         get { throw new NotSupportedException (); }
657                 }
658
659                 string format_name (bool full_name, bool assembly_qualified)
660                 {
661                         StringBuilder sb = new StringBuilder (generic_type.FullName);
662                         bool compiler_ctx = generic_type.IsCompilerContext;
663
664                         sb.Append ("[");
665                         for (int i = 0; i < type_arguments.Length; ++i) {
666                                 if (i > 0)
667                                         sb.Append (",");
668                                 
669                                 string name = full_name ? type_arguments [i].AssemblyQualifiedName : type_arguments [i].ToString ();
670                                 if (name == null) {
671                                         if (compiler_ctx && type_arguments [i].IsGenericParameter)
672                                                 name = type_arguments [i].Name;
673                                         else
674                                                 return null;
675                                 }
676                                 if (full_name)
677                                         sb.Append ("[");
678                                 sb.Append (name);
679                                 if (full_name)
680                                         sb.Append ("]");
681                         }
682                         sb.Append ("]");
683                         if (assembly_qualified) {
684                                 sb.Append (", ");
685                                 sb.Append (generic_type.Assembly.FullName);
686                         }
687                         return sb.ToString ();
688                 }
689
690                 public override string ToString ()
691                 {
692                         return format_name (false, false);
693                 }
694
695                 public override Type MakeArrayType ()
696                 {
697                         return new ArrayType (this, 0);
698                 }
699
700                 public override Type MakeArrayType (int rank)
701                 {
702                         if (rank < 1)
703                                 throw new IndexOutOfRangeException ();
704                         return new ArrayType (this, rank);
705                 }
706
707                 public override Type MakeByRefType ()
708                 {
709                         return new ByRefType (this);
710                 }
711
712                 public override Type MakePointerType ()
713                 {
714                         return new PointerType (this);
715                 }
716
717                 /*public override Type GetElementType ()
718                 {
719                         throw new NotSupportedException ();
720                 }*/
721
722                 protected override bool IsCOMObjectImpl ()
723                 {
724                         return false;
725                 }
726
727                 protected override bool IsPrimitiveImpl ()
728                 {
729                         return false;
730                 }
731
732                 /*
733                 protected override bool IsArrayImpl ()
734                 {
735                         return false;
736                 }
737
738                 protected override bool IsByRefImpl ()
739                 {
740                         return false;
741                 }
742
743                 protected override bool IsPointerImpl ()
744                 {
745                         return false;
746                 }*/
747
748                 protected override TypeAttributes GetAttributeFlagsImpl ()
749                 {
750                         return generic_type.Attributes; 
751                 }
752
753                 //stuff that throws
754                 public override Type GetInterface (string name, bool ignoreCase)
755                 {
756                         throw new NotSupportedException ();
757                 }
758
759                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
760                 {
761                         if (!generic_type.IsCompilerContext)
762                                 throw new NotSupportedException ();
763                         foreach (var evt in GetEvents (bindingAttr)) {
764                                 if (evt.Name == name)
765                                         return evt;
766                         }
767                         return null;
768                 }
769
770                 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
771                 {
772                         throw new NotSupportedException ();
773                 }
774
775                 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
776                 {
777                         throw new NotSupportedException ();
778                 }
779
780                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
781                 {
782                         throw new NotSupportedException ();
783                 }
784
785                 public override object InvokeMember (string name, BindingFlags invokeAttr,
786                                                      Binder binder, object target, object[] args,
787                                                      ParameterModifier[] modifiers,
788                                                      CultureInfo culture, string[] namedParameters)
789                 {
790                         throw new NotSupportedException ();
791                 }
792
793                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
794                                                              CallingConventions callConvention, Type[] types,
795                                                              ParameterModifier[] modifiers)
796                 {
797                         throw new NotSupportedException ();
798                 }
799
800                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
801                                                                  Type returnType, Type[] types, ParameterModifier[] modifiers)
802                 {
803                         throw new NotSupportedException ();
804                 }
805
806                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
807                                                                        Binder binder,
808                                                                        CallingConventions callConvention,
809                                                                        Type[] types,
810                                                                        ParameterModifier[] modifiers)
811                 {
812                         throw new NotSupportedException ();
813                 }
814
815                 //MemberInfo
816                 public override bool IsDefined (Type attributeType, bool inherit)
817                 {
818                         throw new NotSupportedException ();
819                 }
820
821                 public override object [] GetCustomAttributes (bool inherit)
822                 {
823                         throw new NotSupportedException ();
824                 }
825
826                 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
827                 {
828                         throw new NotSupportedException ();
829                 }
830         }
831 }
832