* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
index 5b6d8e0fcf81f34709527e28d026096a4ffd8543..b668caa3b379c81aa3dcb7e4a8208177d310a723 100644 (file)
@@ -6,16 +6,41 @@
 // (C) 2004 Novell, Inc.
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 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_1_2
+#if NET_2_0 || BOOTSTRAP_NET_2_0
 namespace System.Reflection.Emit
 {
+       [ComVisible (true)]
        public sealed class GenericTypeParameterBuilder : Type
        {
        #region Sync with reflection.h
@@ -25,9 +50,8 @@ namespace System.Reflection.Emit
                private int index;
                private Type base_type;
                private Type[] iface_constraints;
-               private bool has_ctor_constraint;
-               private bool has_reference_type;
-               private bool has_value_type;
+               private CustomAttributeBuilder[] cattrs;
+               private GenericParameterAttributes attrs;
        #endregion
 
                public void SetBaseTypeConstraint (Type base_type_constraint)
@@ -35,24 +59,15 @@ namespace System.Reflection.Emit
                        this.base_type = base_type_constraint;
                }
 
+               [ComVisible (true)]
                public void SetInterfaceConstraints (Type[] iface_constraints)
                {
                        this.iface_constraints = iface_constraints;
                }
 
-               public void Mono_SetConstructorConstraint ()
-               {
-                       has_ctor_constraint = true;
-               }
-
-               public void Mono_SetReferenceTypeConstraint ()
-               {
-                       has_reference_type = true;
-               }
-
-               public void Mono_SetValueTypeConstraint ()
+               public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
                {
-                       has_value_type = true;
+                       this.attrs = attrs;
                }
 
                internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
@@ -200,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,
@@ -220,7 +233,7 @@ namespace System.Reflection.Emit
 
                public override Type UnderlyingSystemType {
                        get {
-                               return null;
+                               return this;
                        }
                }
 
@@ -276,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 {
@@ -304,12 +315,8 @@ namespace System.Reflection.Emit
                        throw not_supported ();
                }
 
-               public override bool HasGenericArguments {
-                       get { return false; }
-               }
-
                public override bool ContainsGenericParameters {
-                       get { return false; }
+                       get { return true; }
                }
 
                public override bool IsGenericParameter {
@@ -320,10 +327,50 @@ namespace System.Reflection.Emit
                        get { return index; }
                }
 
-               public override MethodInfo DeclaringMethod {
+               public override GenericParameterAttributes GenericParameterAttributes {
+                       get {
+                               return attrs;
+                       }
+               }
+
+               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;
+               }
+
+               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 ();