Merge pull request #323 from crazyjncsu/master
[mono.git] / mcs / class / corlib / System.Reflection / MonoGenericClass.cs
index cc5a37e806087a93924a109e6e2307c6add1a4c3..9e6d28c61a9d8bbc578d64b830437983bf581e5f 100644 (file)
@@ -38,6 +38,7 @@ using System.Runtime.CompilerServices;
 using System.Globalization;
 using System.Runtime.Serialization;
 using System.Text;
+using System.Runtime.InteropServices;
 
 namespace System.Reflection
 {
@@ -47,34 +48,63 @@ namespace System.Reflection
         * NotImplementedException for many of the methods but we can't do that as gmcs
         * depends on them.
         */
-       internal class MonoGenericClass : MonoType
+       [StructLayout (LayoutKind.Sequential)]
+       internal class MonoGenericClass : Type
        {
                #region Keep in sync with object-internals.h
 #pragma warning disable 649
-               internal TypeBuilder generic_type;
+               internal Type generic_type;
                Type[] type_arguments;
                bool initialized;
 #pragma warning restore 649
                #endregion
 
                Hashtable fields, ctors, methods;
-               int event_count;
 
                internal MonoGenericClass ()
-                       : base (null)
                {
                        // this should not be used
                        throw new InvalidOperationException ();
                }
 
-               internal MonoGenericClass (TypeBuilder tb, Type[] args) : base (null)
+               internal MonoGenericClass (Type tb, Type[] args)
                {
                        this.generic_type = tb;
                        this.type_arguments = args;
+                       /*
+                       This is a temporary hack until we can fix the rest of the runtime
+                       to properly handle this class to be a complete UT.
+
+                       We must not regisrer this with the runtime after the type is created
+                       otherwise created_type.MakeGenericType will return an instance of MonoGenericClass,
+                       which is very very broken.
+                       */
+                       if (tb is TypeBuilder && !(tb as TypeBuilder).is_created)
+                               register_with_runtime (this);
+                       
+               }
+
+               internal override Type InternalResolve ()
+               {
+                       Type gtd = generic_type.InternalResolve ();
+                       Type[] args = new Type [type_arguments.Length];
+                       for (int i = 0; i < type_arguments.Length; ++i)
+                               args [i] = type_arguments [i].InternalResolve ();
+                       return gtd.MakeGenericType (args);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
+               extern void initialize (FieldInfo[] fields);
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern void register_with_runtime (Type type);
+
+               internal bool IsCreated {
+                       get {
+                               TypeBuilder tb = generic_type as TypeBuilder;
+                               return tb != null ? tb.is_created : true;
+                       }
+               }
 
                private const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
@@ -87,14 +117,8 @@ namespace System.Reflection
                        MonoGenericClass parent = GetParentType () as MonoGenericClass;
                        if (parent != null)
                                parent.initialize ();
-                       EventInfo[] events = generic_type.GetEvents_internal (flags);
-                       event_count = events.Length;
                                
-                       initialize (generic_type.GetMethods (flags),
-                                               generic_type.GetConstructorsInternal (flags),
-                                               generic_type.GetFields (flags),
-                                               generic_type.GetProperties (flags),
-                                               events);
+                       initialize (generic_type.GetFields (flags));
 
                        initialized = true;
                }
@@ -106,10 +130,15 @@ namespace System.Reflection
 
                internal Type InflateType (Type type)
                {
-                       return InflateType (type, null);
+                       return InflateType (type, type_arguments, null);
                }
 
                internal Type InflateType (Type type, Type[] method_args)
+               {
+                       return InflateType (type, type_arguments, method_args);
+               }
+
+               internal static Type InflateType (Type type, Type[] type_args, Type[] method_args)
                {
                        if (type == null)
                                return null;
@@ -117,57 +146,37 @@ namespace System.Reflection
                                return type;
                        if (type.IsGenericParameter) {
                                if (type.DeclaringMethod == null)
-                                       return type_arguments [type.GenericParameterPosition];
-                               if (method_args != null)
-                                       return method_args [type.GenericParameterPosition];
-                               return type;
+                                       return type_args == null ? type : type_args [type.GenericParameterPosition];
+                               return method_args == null ? type : method_args [type.GenericParameterPosition];
                        }
                        if (type.IsPointer)
-                               return InflateType (type.GetElementType (), method_args).MakePointerType ();
+                               return InflateType (type.GetElementType (), type_args, method_args).MakePointerType ();
                        if (type.IsByRef)
-                               return InflateType (type.GetElementType (), method_args).MakeByRefType ();
+                               return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
                        if (type.IsArray) {
                                if (type.GetArrayRank () > 1)
-                                       return InflateType (type.GetElementType (), method_args).MakeArrayType (type.GetArrayRank ());
-#if BOOTSTRAP_NET_2_0
-                               if (type.ToString ().EndsWith ("[*]"))
-#else
+                                       return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (type.GetArrayRank ());
+                               
                                if (type.ToString ().EndsWith ("[*]", StringComparison.Ordinal)) /*FIXME, the reflection API doesn't offer a way around this*/
-#endif
-                                       return InflateType (type.GetElementType (), method_args).MakeArrayType (1);
-                               return InflateType (type.GetElementType (), method_args).MakeArrayType ();
+                                       return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType (1);
+                               return InflateType (type.GetElementType (), type_args, method_args).MakeArrayType ();
                        }
 
                        Type[] args = type.GetGenericArguments ();
                        for (int i = 0; i < args.Length; ++i)
-                               args [i] = InflateType (args [i], method_args);
+                               args [i] = InflateType (args [i], type_args, method_args);
 
                        Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
                        return gtd.MakeGenericType (args);
                }
                
                public override Type BaseType {
-                       get {
-                               Type parent = GetParentType ();
-                               return parent != null ? parent : generic_type.BaseType;
-                       }
-               }
-
-               Type[] GetInterfacesInternal ()
-               {
-                       if (generic_type.interfaces == null)
-                               return new Type [0];
-                       Type[] res = new Type [generic_type.interfaces.Length];
-                       for (int i = 0; i < res.Length; ++i)
-                               res [i] = InflateType (generic_type.interfaces [i]);
-                       return res;
+                       get { return generic_type.BaseType; }
                }
 
                public override Type[] GetInterfaces ()
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-                       return GetInterfacesInternal ();
+                       throw new NotSupportedException ();
                }
 
                protected override bool IsValueTypeImpl ()
@@ -179,460 +188,81 @@ namespace System.Reflection
                {
                        initialize ();
 
-                       if (!(fromNoninstanciated is MethodBuilder))
-                               throw new InvalidOperationException ("Inflating non MethodBuilder objects is not supported: " + fromNoninstanciated.GetType ());
-       
-                       MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
                        if (methods == null)
                                methods = new Hashtable ();
-                       if (!methods.ContainsKey (mb))
-                               methods [mb] = new MethodOnTypeBuilderInst (this, mb);
-                       return (MethodInfo)methods [mb];
+                       if (!methods.ContainsKey (fromNoninstanciated))
+                               methods [fromNoninstanciated] = new MethodOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (MethodInfo)methods [fromNoninstanciated];
                }
 
                internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
                {
                        initialize ();
 
-                       if (!(fromNoninstanciated is ConstructorBuilder))
-                               throw new InvalidOperationException ("Inflating non ConstructorBuilder objects is not supported: " + fromNoninstanciated.GetType ());
-
-                       ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
                        if (ctors == null)
                                ctors = new Hashtable ();
-                       if (!ctors.ContainsKey (cb))
-                               ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
-                       return (ConstructorInfo)ctors [cb];
+                       if (!ctors.ContainsKey (fromNoninstanciated))
+                               ctors [fromNoninstanciated] = new ConstructorOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (ConstructorInfo)ctors [fromNoninstanciated];
                }
 
                internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
                {
                        initialize ();
-
-                       if (!(fromNoninstanciated is FieldBuilder))
-                               throw new InvalidOperationException ("Inflating non FieldBuilder objects is not supported: " + fromNoninstanciated.GetType ());
-
-                       FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
                        if (fields == null)
                                fields = new Hashtable ();
-                       if (!fields.ContainsKey (fb))
-                               fields [fb] = new FieldOnTypeBuilderInst (this, fb);
-                       return (FieldInfo)fields [fb];
+                       if (!fields.ContainsKey (fromNoninstanciated))
+                               fields [fromNoninstanciated] = new FieldOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (FieldInfo)fields [fromNoninstanciated];
                }
                
                public override MethodInfo[] GetMethods (BindingFlags bf)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-
-                       ArrayList l = new ArrayList ();
-
-                       //
-                       // Walk up our class hierarchy and retrieve methods from our
-                       // parent classes.
-                       //
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetMethodsInternal (bf, this));
-                               else if (current_type is TypeBuilder)
-                                       l.AddRange (current_type.GetMethods (bf));
-                               else {
-                                       // If we encounter a `MonoType', its
-                                       // GetMethodsByName() will return all the methods
-                                       // from its parent type(s), so we can stop here.
-                                       MonoType mt = (MonoType) current_type;
-                                       l.AddRange (mt.GetMethodsByName (null, bf, false, this));
-                                       break;
-                               }
-
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
-
-                       MethodInfo[] result = new MethodInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
-               }
-
-               MethodInfo[] GetMethodsInternal (BindingFlags bf, MonoGenericClass reftype)
-               {
-                       if (generic_type.num_methods == 0)
-                               return new MethodInfo [0];
-
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-
-                       initialize ();
-
-                       for (int i = 0; i < generic_type.num_methods; ++i) {
-                               MethodInfo c = generic_type.methods [i];
-
-                               match = false;
-                               mattrs = c.Attributes;
-                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               match = false;
-                               if ((mattrs & MethodAttributes.Static) != 0) {
-                                       if ((bf & BindingFlags.Static) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.Instance) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               c = TypeBuilder.GetMethod (this, c);
-                               l.Add (c);
-                       }
-
-                       MethodInfo[] result = new MethodInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+                       throw new NotSupportedException ();
                }
 
                public override ConstructorInfo[] GetConstructors (BindingFlags bf)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetConstructorsInternal (bf, this));
-                               else if (current_type is TypeBuilder)
-                                       l.AddRange (current_type.GetConstructors (bf));
-                               else {
-                                       MonoType mt = (MonoType) current_type;
-                                       l.AddRange (mt.GetConstructors_internal (bf, this));
-                                       break;
-                               }
-
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
-
-                       ConstructorInfo[] result = new ConstructorInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
-               }
-
-               ConstructorInfo[] GetConstructorsInternal (BindingFlags bf, MonoGenericClass reftype)
-               {
-                       if (generic_type.ctors == null)
-                               return new ConstructorInfo [0];
-
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-
-                       initialize ();
-
-                       for (int i = 0; i < generic_type.ctors.Length; i++) {
-                               ConstructorInfo c = generic_type.ctors [i];
-
-                               match = false;
-                               mattrs = c.Attributes;
-                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               match = false;
-                               if ((mattrs & MethodAttributes.Static) != 0) {
-                                       if ((bf & BindingFlags.Static) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.Instance) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               l.Add (TypeBuilder.GetConstructor (this, c));
-                       }
-
-                       ConstructorInfo[] result = new ConstructorInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+                       throw new NotSupportedException ();
                }
 
                public override FieldInfo[] GetFields (BindingFlags bf)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetFieldsInternal (bf, this));
-                               else if (current_type is TypeBuilder)
-                                       l.AddRange (current_type.GetFields (bf));
-                               else {
-                                       MonoType mt = (MonoType) current_type;
-                                       l.AddRange (mt.GetFields_internal (bf, this));
-                                       break;
-                               }
-
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
-
-                       FieldInfo[] result = new FieldInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
-               }
-
-               FieldInfo[] GetFieldsInternal (BindingFlags bf, MonoGenericClass reftype)
-               {
-                       if (generic_type.num_fields == 0)
-                               return new FieldInfo [0];
-
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       FieldAttributes fattrs;
-
-                       initialize ();
-
-                       for (int i = 0; i < generic_type.num_fields; i++) {
-                               FieldInfo c = generic_type.fields [i];
-
-                               match = false;
-                               fattrs = c.Attributes;
-                               if ((fattrs & FieldAttributes.FieldAccessMask) == FieldAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               match = false;
-                               if ((fattrs & FieldAttributes.Static) != 0) {
-                                       if ((bf & BindingFlags.Static) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.Instance) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               l.Add (TypeBuilder.GetField (this, c));
-                       }
-
-                       FieldInfo[] result = new FieldInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+                       throw new NotSupportedException ();
                }
 
                public override PropertyInfo[] GetProperties (BindingFlags bf)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetPropertiesInternal (bf, this));
-                               else if (current_type is TypeBuilder)
-                                       l.AddRange (current_type.GetProperties (bf));
-                               else {
-                                       MonoType mt = (MonoType) current_type;
-                                       l.AddRange (mt.GetPropertiesByName (null, bf, false, this));
-                                       break;
-                               }
-
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
-
-                       PropertyInfo[] result = new PropertyInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
-               }
-
-               PropertyInfo[] GetPropertiesInternal (BindingFlags bf, MonoGenericClass reftype)
-               {
-                       if (generic_type.properties == null)
-                               return new PropertyInfo [0];
-
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-                       MethodInfo accessor;
-
-                       initialize ();
-
-                       foreach (PropertyInfo pinfo in generic_type.properties) {
-                               match = false;
-                               accessor = pinfo.GetGetMethod (true);
-                               if (accessor == null)
-                                       accessor = pinfo.GetSetMethod (true);
-                               if (accessor == null)
-                                       continue;
-                               mattrs = accessor.Attributes;
-                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               match = false;
-                               if ((mattrs & MethodAttributes.Static) != 0) {
-                                       if ((bf & BindingFlags.Static) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.Instance) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               l.Add (new PropertyOnTypeBuilderInst (reftype, pinfo));
-                       }
-                       PropertyInfo[] result = new PropertyInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+                       throw new NotSupportedException ();
                }
 
                public override EventInfo[] GetEvents (BindingFlags bf)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetEventsInternal (bf, this));
-                               else if (current_type is TypeBuilder)
-                                       l.AddRange (current_type.GetEvents (bf));
-                               else {
-                                       MonoType mt = (MonoType) current_type;
-                                       l.AddRange (mt.GetEvents (bf));
-                                       break;
-                               }
-
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
-
-                       EventInfo[] result = new EventInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
-               }
-       
-               EventInfo[] GetEventsInternal (BindingFlags bf, MonoGenericClass reftype) {
-                       if (generic_type.events == null)
-                               return new EventInfo [0];
-
-                       initialize ();
-
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-                       MethodInfo accessor;
-
-                       for (int i = 0; i < event_count; ++i) {
-                               EventBuilder ev = generic_type.events [i];
-
-                               match = false;
-                               accessor = ev.add_method;
-                               if (accessor == null)
-                                       accessor = ev.remove_method;
-                               if (accessor == null)
-                                       continue;
-                               mattrs = accessor.Attributes;
-                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               match = false;
-                               if ((mattrs & MethodAttributes.Static) != 0) {
-                                       if ((bf & BindingFlags.Static) != 0)
-                                               match = true;
-                               } else {
-                                       if ((bf & BindingFlags.Instance) != 0)
-                                               match = true;
-                               }
-                               if (!match)
-                                       continue;
-                               l.Add (new EventOnTypeBuilderInst (this, ev));
-                       }
-                       EventInfo[] result = new EventInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+                       throw new NotSupportedException ();
                }
 
                public override Type[] GetNestedTypes (BindingFlags bf)
                {
-                       return generic_type.GetNestedTypes (bf);
+                       throw new NotSupportedException ();
                }
 
                public override bool IsAssignableFrom (Type c)
                {
-                       if (c == this)
-                               return true;
-
-                       Type[] interfaces = GetInterfacesInternal ();
-
-                       if (c.IsInterface) {
-                               if (interfaces == null)
-                                       return false;
-                               foreach (Type t in interfaces)
-                                       if (c.IsAssignableFrom (t))
-                                               return true;
-                               return false;
-                       }
-
-                       Type parent = GetParentType ();
-                       if (parent == null)
-                               return c == typeof (object);
-                       else
-                               return c.IsAssignableFrom (parent);
+                       throw new NotSupportedException ();
                }
 
                public override Type UnderlyingSystemType {
                        get { return this; }
                }
 
+               public override Assembly Assembly {
+                       get { return generic_type.Assembly; }
+               }
+
+               public override Module Module {
+                       get { return generic_type.Module; }
+               }
+
                public override string Name {
                        get { return generic_type.Name; }
                }
@@ -656,19 +286,23 @@ namespace System.Reflection
                string format_name (bool full_name, bool assembly_qualified)
                {
                        StringBuilder sb = new StringBuilder (generic_type.FullName);
-                       bool compiler_ctx = generic_type.IsCompilerContext;
 
                        sb.Append ("[");
                        for (int i = 0; i < type_arguments.Length; ++i) {
                                if (i > 0)
                                        sb.Append (",");
                                
-                               string name = full_name ? type_arguments [i].AssemblyQualifiedName : type_arguments [i].ToString ();
+                               string name;
+                               if (full_name) {
+                                       string assemblyName = type_arguments [i].Assembly.FullName;
+                                       name = type_arguments [i].FullName;
+                                       if (name != null && assemblyName != null)
+                                               name = name + ", " + assemblyName;
+                               } else {
+                                       name = type_arguments [i].ToString ();
+                               }
                                if (name == null) {
-                                       if (compiler_ctx && type_arguments [i].IsGenericParameter)
-                                               name = type_arguments [i].Name;
-                                       else
-                                               return null;
+                                       return null;
                                }
                                if (full_name)
                                        sb.Append ("[");
@@ -689,6 +323,46 @@ namespace System.Reflection
                        return format_name (false, false);
                }
 
+               public override Type GetGenericTypeDefinition ()
+               {
+                       return generic_type;
+               }
+
+               public override Type[] GetGenericArguments ()
+               {
+                       Type[] ret = new Type [type_arguments.Length];
+                       type_arguments.CopyTo (ret, 0);
+                       return ret;
+               }
+
+               public override bool ContainsGenericParameters {
+                       get {
+                               foreach (Type t in type_arguments) {
+                                       if (t.ContainsGenericParameters)
+                                               return true;
+                               }
+                               return false;
+                       }
+               }
+
+               public override bool IsGenericTypeDefinition {
+                       get { return false; }
+               }
+
+               public override bool IsGenericType {
+                       get { return true; }
+               }
+
+               public override Type DeclaringType {
+                       get { return generic_type.DeclaringType; }
+               }
+
+               public override RuntimeTypeHandle TypeHandle {
+                       get {
+                               throw new NotSupportedException ();
+                       }
+               }
+
                public override Type MakeArrayType ()
                {
                        return new ArrayType (this, 0);
@@ -711,10 +385,15 @@ namespace System.Reflection
                        return new PointerType (this);
                }
 
-               /*public override Type GetElementType ()
+               public override Type GetElementType ()
                {
                        throw new NotSupportedException ();
-               }*/
+               }
+
+               protected override bool HasElementTypeImpl ()
+               {
+                       return false;
+               }
 
                protected override bool IsCOMObjectImpl ()
                {
@@ -726,7 +405,6 @@ namespace System.Reflection
                        return false;
                }
 
-               /*
                protected override bool IsArrayImpl ()
                {
                        return false;
@@ -740,7 +418,7 @@ namespace System.Reflection
                protected override bool IsPointerImpl ()
                {
                        return false;
-               }*/
+               }
 
                protected override TypeAttributes GetAttributeFlagsImpl ()
                {
@@ -755,13 +433,7 @@ namespace System.Reflection
 
                public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
                {
-                       if (!generic_type.IsCompilerContext)
-                               throw new NotSupportedException ();
-                       foreach (var evt in GetEvents (bindingAttr)) {
-                               if (evt.Name == name)
-                                       return evt;
-                       }
-                       return null;
+                       throw new NotSupportedException ();
                }
 
                public override FieldInfo GetField( string name, BindingFlags bindingAttr)
@@ -824,6 +496,17 @@ namespace System.Reflection
                {
                        throw new NotSupportedException ();
                }
+
+               internal override bool IsUserType {
+                       get {
+                               foreach (var t in type_arguments) {
+                                       if (t.IsUserType)
+                                               return true;
+                               }
+                               return false;
+                       }
+               }
+
        }
 }