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
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)
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;
}
- public void Mono_SetConstructorConstraint ()
+ public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
{
- has_ctor_constraint = true;
- }
-
- public void Mono_SetReferenceTypeConstraint ()
- {
- has_reference_type = true;
- }
-
- public void Mono_SetValueTypeConstraint ()
- {
- has_value_type = true;
+ this.attrs = attrs;
}
internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
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,
public override Type UnderlyingSystemType {
get {
- return null;
+ return this;
}
}
}
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 {
throw not_supported ();
}
- public override bool HasGenericArguments {
- get { return false; }
- }
-
public override bool ContainsGenericParameters {
- get { return false; }
+ get { return true; }
}
public override bool IsGenericParameter {
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 ();