diff options
author | jfrijters <jfrijters> | 2011-03-21 07:47:37 +0300 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-03-21 07:47:37 +0300 |
commit | 3991b6b7b982fdb90eeca3c081902603ee658458 (patch) | |
tree | abdc896a12f821c81c771ffddffc152f19d44df8 /reflect/Type.cs | |
parent | 7ce07ae6bcb17af6a3976be414e78185c77d73a0 (diff) |
Use a bit in typeFlags to mark System.Enum and System.ValueType and detect them dynamically, to allow multiple mscorlib versions to be used.
Diffstat (limited to 'reflect/Type.cs')
-rw-r--r-- | reflect/Type.cs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/reflect/Type.cs b/reflect/Type.cs index b4ed9b80..d4870d92 100644 --- a/reflect/Type.cs +++ b/reflect/Type.cs @@ -55,9 +55,12 @@ namespace IKVM.Reflection HasNestedTypes = 2, Baked = 4, - // for general use + // for use by MissingType ValueType = 8, NotValueType = 16, + + // for use by TypeDef, TypeBuilder or MissingType + EnumOrValueType = 32, } // prevent subclassing by outsiders @@ -68,7 +71,9 @@ namespace IKVM.Reflection internal Type(Type underlyingType) { + System.Diagnostics.Debug.Assert(underlyingType.underlyingType == underlyingType); this.underlyingType = underlyingType; + this.typeFlags = underlyingType.typeFlags; } public static Binder DefaultBinder @@ -181,8 +186,9 @@ namespace IKVM.Reflection get { Type baseType = this.BaseType; - return baseType == this.Module.universe.System_Enum - || (baseType == this.Module.universe.System_ValueType && this != this.Module.universe.System_Enum); + return baseType != null + && (baseType.typeFlags & TypeFlags.EnumOrValueType) != 0 + && (typeFlags & TypeFlags.EnumOrValueType) == 0; } } @@ -1053,7 +1059,13 @@ namespace IKVM.Reflection public bool IsEnum { - get { return this.BaseType == this.Module.universe.System_Enum; } + get + { + Type baseType = this.BaseType; + return baseType != null + && (baseType.typeFlags & TypeFlags.EnumOrValueType) != 0 + && baseType.__Name[0] == 'E'; + } } public bool IsSealed @@ -1698,6 +1710,18 @@ namespace IKVM.Reflection { return this; } + + protected void MarkEnumOrValueType(string typeNamespace, string typeName) + { + // we don't assume that mscorlib won't have nested types with these names, + // so we don't check that we're not a nested type + if (typeNamespace == "System" + && (typeName == "Enum" || typeName == "ValueType") + && this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)) + { + typeFlags |= TypeFlags.EnumOrValueType; + } + } } abstract class ElementHolderType : Type |