Merge pull request #498 from Unroll-Me/master
[mono.git] / mcs / class / corlib / System.Reflection / MonoGenericClass.cs
index b229d069492f0e371c12ea33da34e287b1a6df08..ad5e9436fee22d32349fc7aa8367d1f5e8b6f1e1 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#if !FULL_AOT_RUNTIME
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Collections;
 using System.Runtime.CompilerServices;
 using System.Globalization;
 using System.Runtime.Serialization;
-
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+using System.Text;
+using System.Runtime.InteropServices;
 
 namespace System.Reflection
 {
@@ -48,48 +49,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
-               protected TypeBuilder generic_type;
+#pragma warning disable 649
+               internal Type generic_type;
+               Type[] type_arguments;
                bool initialized;
+#pragma warning restore 649
                #endregion
 
                Hashtable fields, ctors, methods;
 
                internal MonoGenericClass ()
-                       : base (null)
                {
                        // this should not be used
                        throw new InvalidOperationException ();
                }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern void initialize (MethodInfo[] methods, ConstructorInfo[] ctors, FieldInfo[] fields, PropertyInfo[] properties, EventInfo[] events);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern MethodInfo GetCorrespondingInflatedMethod (MethodInfo generic);
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern FieldInfo GetCorrespondingInflatedField (string generic);
-               
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern MethodInfo[] GetMethods_internal (Type reflected_type);
+               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);
+                       
+               }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern ConstructorInfo[] GetConstructors_internal (Type reflected_type);
+               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)]
-               protected extern FieldInfo[] GetFields_internal (Type reflected_type);
+               extern void initialize (FieldInfo[] fields);
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern PropertyInfo[] GetProperties_internal (Type reflected_type);
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern void register_with_runtime (Type type);
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern EventInfo[] GetEvents_internal (Type reflected_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;
@@ -102,42 +118,66 @@ namespace System.Reflection
                        MonoGenericClass parent = GetParentType () as MonoGenericClass;
                        if (parent != null)
                                parent.initialize ();
-
-                       initialize (generic_type.GetMethods (flags),
-                                               generic_type.GetConstructors (flags),
-                                               generic_type.GetFields (flags),
-                                               generic_type.GetProperties (flags),
-                                               generic_type.GetEvents_internal (flags));
+                               
+                       initialize (generic_type.GetFields (flags));
 
                        initialized = true;
                }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern Type GetParentType ();
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern Type InflateType_internal (Type type);
+               Type GetParentType ()
+               {
+                       return InflateType (generic_type.BaseType);             
+               }
 
                internal Type InflateType (Type type)
                {
+                       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;
                        if (!type.IsGenericParameter && !type.ContainsGenericParameters)
                                return type;
-                       return InflateType_internal (type);
+                       if (type.IsGenericParameter) {
+                               if (type.DeclaringMethod == null)
+                                       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 (), type_args, method_args).MakePointerType ();
+                       if (type.IsByRef)
+                               return InflateType (type.GetElementType (), type_args, method_args).MakeByRefType ();
+                       if (type.IsArray) {
+                               if (type.GetArrayRank () > 1)
+                                       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*/
+                                       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], type_args, method_args);
+
+                       Type gtd = type.IsGenericTypeDefinition ? type : type.GetGenericTypeDefinition ();
+                       return gtd.MakeGenericType (args);
                }
                
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               protected extern MonoGenericClass[] GetInterfaces_internal ();
-
                public override Type BaseType {
-                       get {
-                               Type parent = GetParentType ();
-                               return parent != null ? parent : generic_type.BaseType;
-                       }
+                       get { return generic_type.BaseType; }
                }
 
                public override Type[] GetInterfaces ()
                {
-                       return GetInterfaces_internal ();
+                       throw new NotSupportedException ();
                }
 
                protected override bool IsValueTypeImpl ()
@@ -149,491 +189,325 @@ namespace System.Reflection
                {
                        initialize ();
 
-#if NET_2_0
-                       if (fromNoninstanciated is MethodOnTypeBuilderInst) {
-                               MethodOnTypeBuilderInst mbinst = (MethodOnTypeBuilderInst)fromNoninstanciated;
-                               if (((ModuleBuilder)mbinst.mb.Module).assemblyb.IsCompilerContext)
-                                       fromNoninstanciated = mbinst.mb;
-                               else
-                                       throw new ArgumentException ("method declaring type is not the generic type definition of type", "method");
-                       }
-
-                       if (fromNoninstanciated is MethodBuilder) {
-                               MethodBuilder mb = (MethodBuilder)fromNoninstanciated;
-
-                               // FIXME: We can't yet handle creating generic instantiations of
-                               // MethodOnTypeBuilderInst objects
-                               // Also, mono_image_get_method_on_inst_token () can't handle generic
-                               // methods
-                               if (!mb.IsGenericMethodDefinition) {
-                                       if (methods == null)
-                                               methods = new Hashtable ();
-                                       if (!methods.ContainsKey (mb))
-                                               methods [mb] = new MethodOnTypeBuilderInst (this, mb);
-                                       return (MethodInfo)methods [mb];
-                               }
-                       }
-#endif
-
-                       return GetCorrespondingInflatedMethod (fromNoninstanciated);
+                       if (methods == null)
+                               methods = new Hashtable ();
+                       if (!methods.ContainsKey (fromNoninstanciated))
+                               methods [fromNoninstanciated] = new MethodOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (MethodInfo)methods [fromNoninstanciated];
                }
 
                internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
                {
                        initialize ();
-               
-#if NET_2_0
-                       if (fromNoninstanciated is ConstructorBuilder) {
-                               ConstructorBuilder cb = (ConstructorBuilder)fromNoninstanciated;
-                               if (ctors == null)
-                                       ctors = new Hashtable ();
-                               if (!ctors.ContainsKey (cb))
-                                       ctors [cb] = new ConstructorOnTypeBuilderInst (this, cb);
-                               return (ConstructorInfo)ctors [cb];
-                       }
-                       
-#endif
-                       return GetCorrespondingInflatedConstructor (fromNoninstanciated);
+
+                       if (ctors == null)
+                               ctors = new Hashtable ();
+                       if (!ctors.ContainsKey (fromNoninstanciated))
+                               ctors [fromNoninstanciated] = new ConstructorOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (ConstructorInfo)ctors [fromNoninstanciated];
                }
 
                internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
                {
                        initialize ();
-
-#if NET_2_0
-                       if (fromNoninstanciated is FieldBuilder) {
-                               FieldBuilder fb = (FieldBuilder)fromNoninstanciated;
-                               if (fields == null)
-                                       fields = new Hashtable ();
-                               if (!fields.ContainsKey (fb))
-                                       fields [fb] = new FieldOnTypeBuilderInst (this, fb);
-                               return (FieldInfo)fields [fb];
-                       }
-#endif
-                       return GetCorrespondingInflatedField (fromNoninstanciated.Name);
+                       if (fields == null)
+                               fields = new Hashtable ();
+                       if (!fields.ContainsKey (fromNoninstanciated))
+                               fields [fromNoninstanciated] = new FieldOnTypeBuilderInst (this, fromNoninstanciated);
+                       return (FieldInfo)fields [fromNoninstanciated];
                }
                
                public override MethodInfo[] GetMethods (BindingFlags bf)
                {
-                       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.GetMethods_impl (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;
-                               }
+                       throw new NotSupportedException ();
+               }
 
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
+               public override ConstructorInfo[] GetConstructors (BindingFlags bf)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       MethodInfo[] result = new MethodInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override FieldInfo[] GetFields (BindingFlags bf)
+               {
+                       throw new NotSupportedException ();
                }
 
-               protected MethodInfo[] GetMethods_impl (BindingFlags bf, Type reftype)
+               public override PropertyInfo[] GetProperties (BindingFlags bf)
                {
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
+                       throw new NotSupportedException ();
+               }
 
-                       initialize ();
+               public override EventInfo[] GetEvents (BindingFlags bf)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       MethodInfo[] methods = GetMethods_internal (reftype);
+               public override Type[] GetNestedTypes (BindingFlags bf)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       for (int i = 0; i < methods.Length; i++) {
-                               MethodInfo c = methods [i];
+               public override bool IsAssignableFrom (Type c)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                               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 (c);
-                       }
-                       MethodInfo[] result = new MethodInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override Type UnderlyingSystemType {
+                       get { return this; }
                }
 
-               public override ConstructorInfo[] GetConstructors (BindingFlags bf)
-               {
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetConstructors_impl (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;
-                               }
+               public override Assembly Assembly {
+                       get { return generic_type.Assembly; }
+               }
 
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
+               public override Module Module {
+                       get { return generic_type.Module; }
+               }
 
-                       ConstructorInfo[] result = new ConstructorInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override string Name {
+                       get { return generic_type.Name; }
                }
 
-               protected ConstructorInfo[] GetConstructors_impl (BindingFlags bf, Type reftype)
-               {
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
+               public override string Namespace {
+                       get { return generic_type.Namespace; }
+               }
 
-                       initialize ();
+               public override string FullName {
+                       get { return format_name (true, false); }
+               }
 
-                       ConstructorInfo[] ctors = GetConstructors_internal (reftype);
+               public override string AssemblyQualifiedName {
+                       get { return format_name (true, true); }
+               }
 
-                       for (int i = 0; i < ctors.Length; i++) {
-                               ConstructorInfo c = ctors [i];
+               public override Guid GUID {
+                       get { throw new NotSupportedException (); }
+               }
 
-                               match = false;
-                               mattrs = c.Attributes;
-                               if ((mattrs & MethodAttributes.MemberAccessMask) == MethodAttributes.Public) {
-                                       if ((bf & BindingFlags.Public) != 0)
-                                               match = true;
+               string format_name (bool full_name, bool assembly_qualified)
+               {
+                       StringBuilder sb = new StringBuilder (generic_type.FullName);
+
+                       sb.Append ("[");
+                       for (int i = 0; i < type_arguments.Length; ++i) {
+                               if (i > 0)
+                                       sb.Append (",");
+                               
+                               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 {
-                                       if ((bf & BindingFlags.NonPublic) != 0)
-                                               match = true;
+                                       name = type_arguments [i].ToString ();
                                }
-                               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 (name == null) {
+                                       return null;
                                }
-                               if (!match)
-                                       continue;
-                               l.Add (c);
+                               if (full_name)
+                                       sb.Append ("[");
+                               sb.Append (name);
+                               if (full_name)
+                                       sb.Append ("]");
+                       }
+                       sb.Append ("]");
+                       if (assembly_qualified) {
+                               sb.Append (", ");
+                               sb.Append (generic_type.Assembly.FullName);
                        }
+                       return sb.ToString ();
+               }
 
-                       ConstructorInfo[] result = new ConstructorInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override string ToString ()
+               {
+                       return format_name (false, false);
                }
 
-               public override FieldInfo[] GetFields (BindingFlags bf)
+               public override Type GetGenericTypeDefinition ()
                {
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetFields_impl (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;
+                       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;
+                       }
+               }
 
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
+               public override bool IsGenericTypeDefinition {
+                       get { return false; }
+               }
 
-                       FieldInfo[] result = new FieldInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override bool IsGenericType {
+                       get { return true; }
+               }
+
+               public override Type DeclaringType {
+                       get { return generic_type.DeclaringType; }
+               }
+
+               public override RuntimeTypeHandle TypeHandle {
+                       get {
+                               throw new NotSupportedException ();
+                       }
                }
 
-               protected FieldInfo[] GetFields_impl (BindingFlags bf, Type reftype)
+               public override Type MakeArrayType ()
                {
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       FieldAttributes fattrs;
+                       return new ArrayType (this, 0);
+               }
 
-                       initialize ();
+               public override Type MakeArrayType (int rank)
+               {
+                       if (rank < 1)
+                               throw new IndexOutOfRangeException ();
+                       return new ArrayType (this, rank);
+               }
 
-                       FieldInfo[] fields = GetFields_internal (reftype);
+               public override Type MakeByRefType ()
+               {
+                       return new ByRefType (this);
+               }
 
-                       for (int i = 0; i < fields.Length; i++) {
-                               FieldInfo c = fields [i];
+               public override Type MakePointerType ()
+               {
+                       return new PointerType (this);
+               }
 
-                               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 (c);
-                       }
-                       FieldInfo[] result = new FieldInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override Type GetElementType ()
+               {
+                       throw new NotSupportedException ();
                }
 
-               public override PropertyInfo[] GetProperties (BindingFlags bf)
+               protected override bool HasElementTypeImpl ()
                {
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetProperties_impl (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;
-                               }
+                       return false;
+               }
 
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
+               protected override bool IsCOMObjectImpl ()
+               {
+                       return false;
+               }
 
-                       PropertyInfo[] result = new PropertyInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               protected override bool IsPrimitiveImpl ()
+               {
+                       return false;
                }
 
-               protected PropertyInfo[] GetProperties_impl (BindingFlags bf, Type reftype)
+               protected override bool IsArrayImpl ()
                {
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-                       MethodInfo accessor;
+                       return false;
+               }
 
-                       initialize ();
+               protected override bool IsByRefImpl ()
+               {
+                       return false;
+               }
 
-                       PropertyInfo[] properties = GetProperties_internal (reftype);
-
-                       for (int i = 0; i < properties.Length; i++) {
-                               PropertyInfo c = properties [i];
-
-                               match = false;
-                               accessor = c.GetGetMethod (true);
-                               if (accessor == null)
-                                       accessor = c.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 (c);
-                       }
-                       PropertyInfo[] result = new PropertyInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               protected override bool IsPointerImpl ()
+               {
+                       return false;
                }
 
-               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
-                                                                Binder binder, Type returnType,
-                                                                Type[] types,
-                                                                ParameterModifier[] modifiers)
+               protected override TypeAttributes GetAttributeFlagsImpl ()
                {
-                       bool ignoreCase = ((bindingAttr & BindingFlags.IgnoreCase) != 0);
-                       PropertyInfo [] props = GetProperties (bindingAttr);
+                       return generic_type.Attributes; 
+               }
 
-                       ArrayList al = null;
-                       for (int i = 0; i < props.Length; ++i) {
-                               if (String.Compare (props [i].Name, name, ignoreCase) == 0) {
-                                       if (al == null)
-                                               al = new ArrayList ();
-                                       al.Add (props [i]);
-                               }
-                       }
-                       if (al == null)
-                               return null;
+               //stuff that throws
+               public override Type GetInterface (string name, bool ignoreCase)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       props = (PropertyInfo[])al.ToArray (typeof (PropertyInfo));
-                       
-                       int count = props.Length;
-                       
-                       if (count == 1 && (types == null || types.Length == 0) &&
-                           (returnType == null || returnType == props[0].PropertyType))
-                               return props [0];
+               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       if (binder == null)
-                               binder = Binder.DefaultBinder;
-                       
-                       return binder.SelectProperty (bindingAttr, props, returnType, types, modifiers);
+               public override FieldInfo GetField( string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
                }
 
-               public override EventInfo[] GetEvents (BindingFlags bf)
+               public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
                {
-                       ArrayList l = new ArrayList ();
-
-                       Type current_type = this;
-                       do {
-                               MonoGenericClass gi = current_type as MonoGenericClass;
-                               if (gi != null)
-                                       l.AddRange (gi.GetEvents_impl (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;
-                               }
+                       throw new NotSupportedException ();
+               }
 
-                               if ((bf & BindingFlags.DeclaredOnly) != 0)
-                                       break;
-                               current_type = current_type.BaseType;
-                       } while (current_type != null);
+               public override Type GetNestedType (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       EventInfo[] result = new EventInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               public override object InvokeMember (string name, BindingFlags invokeAttr,
+                                                    Binder binder, object target, object[] args,
+                                                    ParameterModifier[] modifiers,
+                                                    CultureInfo culture, string[] namedParameters)
+               {
+                       throw new NotSupportedException ();
                }
 
-               protected EventInfo[] GetEvents_impl (BindingFlags bf, Type reftype)
+               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
+                                                            CallingConventions callConvention, Type[] types,
+                                                            ParameterModifier[] modifiers)
                {
-                       ArrayList l = new ArrayList ();
-                       bool match;
-                       MethodAttributes mattrs;
-                       MethodInfo accessor;
+                       throw new NotSupportedException ();
+               }
 
-                       initialize ();
+               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
+                                                                Type returnType, Type[] types, ParameterModifier[] modifiers)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       EventInfo[] events = GetEvents_internal (reftype);
-
-                       for (int i = 0; i < events.Length; i++) {
-                               EventInfo c = events [i];
-
-                               match = false;
-                               accessor = c.GetAddMethod (true);
-                               if (accessor == null)
-                                       accessor = c.GetRemoveMethod (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 (c);
-                       }
-                       EventInfo[] result = new EventInfo [l.Count];
-                       l.CopyTo (result);
-                       return result;
+               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
+                                                                      Binder binder,
+                                                                      CallingConventions callConvention,
+                                                                      Type[] types,
+                                                                      ParameterModifier[] modifiers)
+               {
+                       throw new NotSupportedException ();
                }
 
-               public override Type[] GetNestedTypes (BindingFlags bf)
+               //MemberInfo
+               public override bool IsDefined (Type attributeType, bool inherit)
                {
-                       return generic_type.GetNestedTypes (bf);
+                       throw new NotSupportedException ();
                }
 
-               public override bool IsAssignableFrom (Type c)
+               public override object [] GetCustomAttributes (bool inherit)
                {
-                       if (c == this)
-                               return true;
+                       throw new NotSupportedException ();
+               }
 
-                       MonoGenericClass[] interfaces = GetInterfaces_internal ();
+               public override object [] GetCustomAttributes (Type attributeType, bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
 
-                       if (c.IsInterface) {
-                               if (interfaces == null)
-                                       return false;
-                               foreach (Type t in interfaces)
-                                       if (c.IsAssignableFrom (t))
+               internal override bool IsUserType {
+                       get {
+                               foreach (var t in type_arguments) {
+                                       if (t.IsUserType)
                                                return true;
+                               }
                                return false;
                        }
-
-                       Type parent = GetParentType ();
-                       if (parent == null)
-                               return c == typeof (object);
-                       else
-                               return c.IsAssignableFrom (parent);
                }
+
        }
 }