* convert.cs (Convert.TypeParameter_to_Null): Use the constraints
to check whether the conversion is ok.
* typemanager.cs (TypeManager.GetTypeArguments): Just return
`Type.EmptyTypes' if we're not a generic TypeContainer.
svn path=/trunk/mcs/; revision=37098
+2004-12-04 Martin Baulig <martin@ximian.com>
+
+ * convert.cs (Convert.TypeParameter_to_Null): Use the constraints
+ to check whether the conversion is ok.
+
+ * typemanager.cs (TypeManager.GetTypeArguments): Just return
+ `Type.EmptyTypes' if we're not a generic TypeContainer.
+
2004-11-25 Miguel de Icaza <miguel@ximian.com>
* convert.cs (ImplicitReferenceConversionExists): A surprisingly
static bool TypeParameter_to_Null (Type target_type)
{
- if ((target_type.BaseType == null) ||
- (target_type.BaseType == TypeManager.value_type) ||
- target_type.BaseType.IsValueType)
+ GenericConstraints gc = TypeManager.GetTypeParameterConstraints (target_type);
+ if (gc == null)
return false;
- return true;
+ if (gc.HasReferenceTypeConstraint)
+ return true;
+ if (gc.HasClassConstraint && !TypeManager.IsValueType (gc.ClassConstraint))
+ return true;
+
+ return false;
}
static Type TypeParam_EffectiveBaseType (EmitContext ec, Type t)
DeclSpace tc = LookupDeclSpace (t);
if (tc != null) {
if (!tc.IsGeneric)
- throw new InvalidOperationException ();
+ return Type.EmptyTypes;
TypeParameter[] tparam = tc.TypeParameters;
Type[] ret = new Type [tparam.Length];