[sre] Pass declaring type to GetMethodFromHandle in
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
index e32565319c8130964ffa22697a811645ef9cf825..9bbe8d0d92b32f73ee8976d3aa23780a54250672 100644 (file)
@@ -29,6 +29,7 @@
 // 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;
@@ -40,7 +41,9 @@ using System.Runtime.Serialization;
 namespace System.Reflection.Emit
 {
        [ComVisible (true)]
-       public sealed class GenericTypeParameterBuilder : Type
+       [StructLayout (LayoutKind.Sequential)]
+       public sealed class GenericTypeParameterBuilder : 
+               TypeInfo
        {
        #region Sync with reflection.h
                private TypeBuilder tbuilder;
@@ -48,9 +51,11 @@ namespace System.Reflection.Emit
                private string name;
                private int index;
                private Type base_type;
+#pragma warning disable 414
                private Type[] iface_constraints;
                private CustomAttributeBuilder[] cattrs;
                private GenericParameterAttributes attrs;
+#pragma warning restore
        #endregion
 
                public void SetBaseTypeConstraint (Type baseTypeConstraint)
@@ -77,45 +82,31 @@ namespace System.Reflection.Emit
                        this.mbuilder = mbuilder;
                        this.name = name;
                        this.index = index;
-
-                       initialize ();
-               }
-
-
-               internal override bool IsCompilerContext {
-                       get {
-                               return tbuilder.IsCompilerContext;
-                       }
                }
 
                internal override Type InternalResolve ()
                {
-                       return tbuilder.InternalResolve ().GetGenericArguments () [index]; 
+                       if (mbuilder != null)
+                               return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.InternalResolve ().TypeHandle).GetGenericArguments () [index];
+                       return tbuilder.InternalResolve ().GetGenericArguments () [index];
                }
 
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern void initialize ();
+               internal override Type RuntimeResolve ()
+               {
+                       if (mbuilder != null)
+                               return MethodBase.GetMethodFromHandle (mbuilder.MethodHandleInternal, mbuilder.TypeBuilder.RuntimeResolve ().TypeHandle).GetGenericArguments () [index];
+                       return tbuilder.RuntimeResolve ().GetGenericArguments () [index];
+               }
 
                [ComVisible (true)]
                public override bool IsSubclassOf (Type c)
                {
-                       if (!IsCompilerContext)
-                               throw not_supported ();
-                       if (BaseType == null)
-                               return false;
-                       else
-                               return BaseType == c || BaseType.IsSubclassOf (c);
+                       throw not_supported ();
                }
 
                protected override TypeAttributes GetAttributeFlagsImpl ()
                {
-#if NET_4_0
                        return TypeAttributes.Public;
-#else
-                       if (IsCompilerContext)
-                               return TypeAttributes.Public;
-                       throw not_supported ();
-#endif
                }
 
                protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
@@ -224,6 +215,14 @@ namespace System.Reflection.Emit
                        throw not_supported ();
                }
 
+               public override bool IsAssignableFrom (TypeInfo typeInfo)
+               {
+                       if (typeInfo == null)
+                               return false;
+
+                       return IsAssignableFrom (typeInfo.AsType ());
+               }
+
                public override bool IsInstanceOfType (object o)
                {
                        throw not_supported ();
@@ -371,8 +370,6 @@ namespace System.Reflection.Emit
 
                public override GenericParameterAttributes GenericParameterAttributes {
                        get {
-                               if (IsCompilerContext)
-                                       return attrs;
                                throw new NotSupportedException ();
                        }
                }
@@ -383,22 +380,7 @@ namespace System.Reflection.Emit
 
                public override Type[] GetGenericParameterConstraints ()
                {
-                       if (!IsCompilerContext)
-                               throw new InvalidOperationException ();
-                       if (base_type == null) {
-                               if (iface_constraints != null)
-                                       return iface_constraints;
-
-                               return Type.EmptyTypes;
-                       }
-
-                       if (iface_constraints == null)
-                               return new Type[] { base_type };
-
-                       Type[] ret = new Type [iface_constraints.Length + 1];
-                       ret [0] = base_type;
-                       iface_constraints.CopyTo (ret, 1);
-                       return ret;
+                       throw new InvalidOperationException ();
                }
 
                public override MethodBase DeclaringMethod {
@@ -466,15 +448,21 @@ namespace System.Reflection.Emit
                        return new ByRefType (this);
                }
 
-               [MonoTODO]
-               public override Type MakeGenericType (params Type [] typeArguments)
+               public override Type MakeGenericType (params Type[] typeArguments)
                {
-                       return base.MakeGenericType (typeArguments);
+                       throw new InvalidOperationException (Environment.GetResourceString ("Arg_NotGenericTypeDefinition"));
                }
 
                public override Type MakePointerType ()
                {
                        return new PointerType (this);
                }
+
+               internal override bool IsUserType {
+                       get {
+                               return false;
+                       }
+               }
        }
 }
+#endif