2007-11-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
index 17763b4b25a08c7b5ec9f4a404d3144a6bbeb0a0..5483f01560f4ab253835eff732bb57aa8d588576 100644 (file)
@@ -33,12 +33,14 @@ using System.Reflection;
 using System.Reflection.Emit;
 using System.Collections;
 using System.Runtime.CompilerServices;
+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
        {
        #region Sync with reflection.h
@@ -48,6 +50,7 @@ namespace System.Reflection.Emit
                private int index;
                private Type base_type;
                private Type[] iface_constraints;
+               private CustomAttributeBuilder[] cattrs;
                private GenericParameterAttributes attrs;
        #endregion
 
@@ -56,7 +59,8 @@ namespace System.Reflection.Emit
                        this.base_type = base_type_constraint;
                }
 
-               public void SetInterfaceConstraints (Type[] iface_constraints)
+               [ComVisible (true)]
+               public void SetInterfaceConstraints (params Type[] iface_constraints)
                {
                        this.iface_constraints = iface_constraints;
                }
@@ -211,9 +215,7 @@ namespace System.Reflection.Emit
 
                protected override bool IsValueTypeImpl ()
                {
-#warning "FIXME"
-                       return false;
-                       // return base_type != null ? base_type.IsValueType : false;
+                       return base_type != null ? base_type.IsValueType : false;
                }
                
                public override object InvokeMember (string name, BindingFlags invokeAttr,
@@ -231,7 +233,7 @@ namespace System.Reflection.Emit
 
                public override Type UnderlyingSystemType {
                        get {
-                               return null;
+                               return this;
                        }
                }
 
@@ -287,13 +289,11 @@ namespace System.Reflection.Emit
                }
 
                public override Type DeclaringType {
-                       get { return mbuilder != null ? null : tbuilder; }
+                       get { return mbuilder != null ? mbuilder.DeclaringType : tbuilder; }
                }
 
                public override Type ReflectedType {
-                       get {
-                               return DeclaringType;
-                       }
+                       get { return DeclaringType; }
                }
 
                public override RuntimeTypeHandle TypeHandle {
@@ -315,10 +315,6 @@ namespace System.Reflection.Emit
                        throw not_supported ();
                }
 
-               public override bool HasGenericArguments {
-                       get { return false; }
-               }
-
                public override bool ContainsGenericParameters {
                        get { return true; }
                }
@@ -343,7 +339,7 @@ namespace System.Reflection.Emit
                                if (iface_constraints != null)
                                        return iface_constraints;
 
-                               return new Type[] { typeof (object) };
+                               return Type.EmptyTypes;
                        }
 
                        if (iface_constraints == null)
@@ -355,10 +351,26 @@ namespace System.Reflection.Emit
                        return ret;
                }
 
-               public override MethodInfo DeclaringMethod {
+               public override MethodBase DeclaringMethod {
                        get { return mbuilder; }
                }
 
+               public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
+               {
+                       if (customBuilder == null)
+                               throw new ArgumentNullException ("customBuilder");
+
+                       if (cattrs != null) {
+                               CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
+                               cattrs.CopyTo (new_array, 0);
+                               new_array [cattrs.Length] = customBuilder;
+                               cattrs = new_array;
+                       } else {
+                               cattrs = new CustomAttributeBuilder [1];
+                               cattrs [0] = customBuilder;
+                       }
+               }
+
                private Exception not_supported ()
                {
                        return new NotSupportedException ();