[sre] Pass declaring type to GetMethodFromHandle in
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
index 259c2a1479b32a1d5cf78204bd808c8700e0616e..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;
@@ -37,11 +38,12 @@ using System.Runtime.InteropServices;
 using System.Globalization;
 using System.Runtime.Serialization;
 
-#if NET_2_0 || BOOTSTRAP_NET_2_0
 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;
@@ -49,25 +51,27 @@ 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 base_type_constraint)
+               public void SetBaseTypeConstraint (Type baseTypeConstraint)
                {
-                       this.base_type = base_type_constraint;
+                       this.base_type = baseTypeConstraint ?? typeof (object);
                }
 
                [ComVisible (true)]
-               public void SetInterfaceConstraints (params Type[] iface_constraints)
+               public void SetInterfaceConstraints (params Type[] interfaceConstraints)
                {
-                       this.iface_constraints = iface_constraints;
+                       this.iface_constraints = interfaceConstraints;
                }
 
-               public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
+               public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
                {
-                       this.attrs = attrs;
+                       this.attrs = genericParameterAttributes;
                }
 
                internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
@@ -78,20 +82,26 @@ namespace System.Reflection.Emit
                        this.mbuilder = mbuilder;
                        this.name = name;
                        this.index = index;
+               }
 
-                       initialize ();
+               internal override Type InternalResolve ()
+               {
+                       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 (BaseType == null)
-                               return false;
-                       else
-                               return BaseType == c || BaseType.IsSubclassOf (c);
+                       throw not_supported ();
                }
 
                protected override TypeAttributes GetAttributeFlagsImpl ()
@@ -205,6 +215,19 @@ 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 ();
+               }
+
                protected override bool IsArrayImpl ()
                {
                        return false;
@@ -271,7 +294,7 @@ namespace System.Reflection.Emit
                }
 
                public override Guid GUID {
-                       get { return Guid.Empty; }
+                       get { throw not_supported (); }
                }
 
                public override bool IsDefined (Type attributeType, bool inherit)
@@ -321,12 +344,12 @@ namespace System.Reflection.Emit
 
                public override Type[] GetGenericArguments ()
                {
-                       throw not_supported ();
+                       throw new InvalidOperationException ();
                }
 
                public override Type GetGenericTypeDefinition ()
                {
-                       throw not_supported ();
+                       throw new InvalidOperationException ();
                }
 
                public override bool ContainsGenericParameters {
@@ -347,7 +370,7 @@ namespace System.Reflection.Emit
 
                public override GenericParameterAttributes GenericParameterAttributes {
                        get {
-                               return attrs;
+                               throw new NotSupportedException ();
                        }
                }
 
@@ -357,20 +380,7 @@ namespace System.Reflection.Emit
 
                public override Type[] GetGenericParameterConstraints ()
                {
-                       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 {
@@ -410,9 +420,9 @@ namespace System.Reflection.Emit
                }
 
                [MonoTODO]
-               public override bool Equals (object other)
+               public override bool Equals (object o)
                {
-                       return base.Equals (other);
+                       return base.Equals (o);
                }
 
                [MonoTODO]
@@ -421,34 +431,37 @@ namespace System.Reflection.Emit
                        return base.GetHashCode ();
                }
 
-               [MonoTODO]
                public override Type MakeArrayType ()
                {
-                       return base.MakeArrayType ();
+                       return  new ArrayType (this, 0);
                }
 
-               [MonoTODO]
                public override Type MakeArrayType (int rank)
                {
-                       return base.MakeArrayType (rank);
+                       if (rank < 1)
+                               throw new IndexOutOfRangeException ();
+                       return new ArrayType (this, rank);
                }
 
-               [MonoTODO]
                public override Type MakeByRefType ()
                {
-                       return base.MakeByRefType ();
+                       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"));
                }
 
-               [MonoTODO]
                public override Type MakePointerType ()
                {
-                       return base.MakePointerType ();
+                       return new PointerType (this);
+               }
+
+               internal override bool IsUserType {
+                       get {
+                               return false;
+                       }
                }
        }
 }