diff --git a/src/System.Private.CoreLib/src/System/Reflection/MethodBase.cs b/src/System.Private.CoreLib/src/System/Reflection/MethodBase.cs index eebbb9c5974..cb255b408ab 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -20,7 +20,6 @@ internal MethodBase() { } - public abstract MethodAttributes Attributes { get; } public virtual CallingConventions CallingConvention { get { return CallingConventions.Standard; } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs index c27e1bf0c58..95d9f744fa3 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/TypeInfo.cs @@ -14,14 +14,13 @@ namespace System.Reflection { - public abstract class TypeInfo : MemberInfo, IReflectableType + public abstract class TypeInfo : Type, IReflectableType { protected TypeInfo() { } public abstract Assembly Assembly { get; } - public abstract String AssemblyQualifiedName { get; } public abstract TypeAttributes Attributes { get; } public abstract Type BaseType { get; } public abstract bool ContainsGenericParameters { get; } @@ -95,10 +94,7 @@ private IEnumerable GetDeclaredMembersOfType() where T : MemberInfo public abstract MethodBase DeclaringMethod { get; } - public abstract String FullName { get; } public abstract GenericParameterAttributes GenericParameterAttributes { get; } - public abstract int GenericParameterPosition { get; } - public abstract Type[] GenericTypeArguments { get; } public virtual Type[] GenericTypeParameters { @@ -117,14 +113,6 @@ public virtual Type[] GenericTypeParameters public abstract Guid GUID { get; } - public bool HasElementType - { - get - { - return IsArray || IsPointer || IsByRef; - } - } - public virtual IEnumerable ImplementedInterfaces { get @@ -151,15 +139,6 @@ public bool IsAnsiClass } } - public bool IsArray - { - get - { - return AsType().IsArray; - } - } - - public bool IsAutoClass { get @@ -176,14 +155,6 @@ public bool IsAutoLayout } } - public bool IsByRef - { - get - { - return AsType().IsByRef; - } - } - public bool IsClass { get @@ -204,7 +175,6 @@ public bool IsExplicitLayout } } - public abstract bool IsGenericParameter { get; } public abstract bool IsGenericType { get; } public abstract bool IsGenericTypeDefinition { get; } @@ -236,14 +206,6 @@ public bool IsLayoutSequential public bool IsMarshalByRef { get { return false; } } - public bool IsNested - { - get - { - return this.DeclaringType != null; - } - } - public bool IsNestedAssembly { get @@ -306,14 +268,6 @@ public bool IsNotPublic } } - public bool IsPointer - { - get - { - return AsType().IsPointer; - } - } - public virtual bool IsPrimitive { get @@ -407,15 +361,11 @@ public bool IsVisible } } - public abstract String Namespace { get; } - public virtual Type AsType() { throw NotImplemented.ByDesign; } - public abstract int GetArrayRank(); - public virtual EventInfo GetDeclaredEvent(String name) { return GetDeclaredMember(name, DeclaredEvents); @@ -470,9 +420,7 @@ private T GetDeclaredMember(String name, IEnumerable members) where T : Me } - public abstract Type GetElementType(); public abstract Type[] GetGenericParameterConstraints(); - public abstract Type GetGenericTypeDefinition(); public virtual bool IsAssignableFrom(TypeInfo typeInfo) { @@ -527,12 +475,9 @@ public virtual bool IsSubclassOf(Type c) return false; } - - public abstract Type MakeArrayType(); - public abstract Type MakeArrayType(int rank); - public abstract Type MakeByRefType(); - public abstract Type MakeGenericType(params Type[] typeArguments); - public abstract Type MakePointerType(); + // TODO https://github.com/dotnet/corefx/issues/9805: This is inherited from Type and shouldn't need to be redeclared on TypeInfo but + // TypeInfo.MakeGenericType is a well known method to the reducer. + public abstract override Type MakeGenericType(params Type[] typeArguments); TypeInfo System.Reflection.IReflectableType.GetTypeInfo() { diff --git a/src/System.Private.CoreLib/src/System/Type.cs b/src/System.Private.CoreLib/src/System/Type.cs index 2c8e57dd514..151d987c430 100644 --- a/src/System.Private.CoreLib/src/System/Type.cs +++ b/src/System.Private.CoreLib/src/System/Type.cs @@ -9,6 +9,7 @@ using System; using System.Threading; using System.Runtime; +using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Collections.Generic; @@ -17,7 +18,7 @@ namespace System { - public abstract class Type + public abstract class Type : MemberInfo { protected Type() { @@ -27,7 +28,6 @@ protected Type() public static readonly Type[] EmptyTypes = Array.Empty(); public abstract String AssemblyQualifiedName { get; } - public abstract Type DeclaringType { get; } public abstract String FullName { get; } public abstract int GenericParameterPosition { get; } public abstract Type[] GenericTypeArguments { get; } @@ -40,19 +40,19 @@ public bool HasElementType } } - public virtual bool IsArray + public bool IsArray { get { - throw NotImplemented.ByDesign; + return IsArrayImpl() ; } } - public virtual bool IsByRef + public bool IsByRef { get { - throw NotImplemented.ByDesign; + return IsByRefImpl(); } } @@ -67,15 +67,14 @@ public bool IsNested } } - public virtual bool IsPointer + public bool IsPointer { get { - throw NotImplemented.ByDesign; + return IsPointerImpl(); } } - public abstract String Name { get; } public abstract String Namespace { get; } public virtual RuntimeTypeHandle TypeHandle @@ -141,6 +140,10 @@ public override int GetHashCode() throw NotImplemented.ByDesign; } + protected abstract bool IsArrayImpl(); + protected abstract bool IsByRefImpl(); + protected abstract bool IsPointerImpl(); + internal bool TryGetEEType(out EETypePtr eeType) { RuntimeTypeHandle typeHandle = RuntimeAugments.Callbacks.GetTypeHandleIfAvailable(this); @@ -154,3 +157,4 @@ internal bool TryGetEEType(out EETypePtr eeType) } } } + diff --git a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs index e49a5e317f6..2fafe4b653d 100644 --- a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs +++ b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs @@ -158,6 +158,11 @@ public override int GetHashCode() { return _fullTypeName.GetHashCode(); } + + protected override bool IsArrayImpl() { throw new System.Reflection.MissingMetadataException(_fullTypeName); } + protected override bool IsByRefImpl() { throw new System.Reflection.MissingMetadataException(_fullTypeName); } + protected override bool IsPointerImpl() { throw new System.Reflection.MissingMetadataException(_fullTypeName); } + #endif //RHTESTCL } diff --git a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/NonPortable/RuntimeType.cs b/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/NonPortable/RuntimeType.cs deleted file mode 100644 index 38ca2e5f4c8..00000000000 --- a/src/System.Private.Reflection.Core/src/Internal/Reflection/Core/NonPortable/RuntimeType.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Reflection; -using System.Diagnostics; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Reflection.Runtime.General; -using System.Reflection.Runtime.TypeInfos; - -using Internal.Reflection.Extensibility; - -namespace Internal.Reflection.Core.NonPortable -{ - // - // TODO https://github.com/dotnet/corefx/issues/9805: - // - // With Type and TypeInfo being merged back into the same object, RuntimeType is being phased out in favor of RuntimeTypeInfo. - // This phaseout will happen slowly since RuntimeType is a widely used exchange type. - // - internal abstract class RuntimeType : ExtensibleType, IEquatable, ICloneable, IReflectableType, IRuntimeImplementedType - { - protected RuntimeType() - : base() - { - } - - public object Clone() - { - return this; - } - - public abstract TypeInfo GetTypeInfo(); - - public abstract override bool Equals(object obj); - public abstract override int GetHashCode(); - - public bool Equals(RuntimeType runtimeType) - { - return object.ReferenceEquals(this, runtimeType); - } - - public abstract override string AssemblyQualifiedName { get; } - public abstract override Type DeclaringType { get; } - public abstract override string FullName { get; } - public abstract override int GenericParameterPosition { get; } - public abstract override Type[] GenericTypeArguments { get; } - public abstract override bool IsArray { get; } - public abstract override bool IsByRef { get; } - public abstract override bool IsConstructedGenericType { get; } - public abstract override bool IsGenericParameter { get; } - public abstract override bool IsPointer { get; } - public abstract override int GetArrayRank(); - public abstract override Type GetElementType(); - public abstract override Type GetGenericTypeDefinition(); - public abstract override Type MakeArrayType(); - public abstract override Type MakeArrayType(int rank); - public abstract override Type MakeByRefType(); - public abstract override Type MakeGenericType(params Type[] instantiation); - public abstract override Type MakePointerType(); - public abstract override string Name { get; } - public abstract override string Namespace { get; } - public abstract override RuntimeTypeHandle TypeHandle { get; } - public abstract override string ToString(); - - internal abstract string InternalFullNameOfAssembly { get; } - internal abstract bool InternalTryGetTypeHandle(out RuntimeTypeHandle typeHandle); - internal abstract bool InternalIsGenericTypeDefinition { get; } - internal abstract RuntimeTypeInfo InternalRuntimeElementType { get; } - internal abstract RuntimeTypeInfo[] InternalRuntimeGenericTypeArguments { get; } - - internal string InternalNameIfAvailable - { - get - { - Type ignore = null; - return InternalGetNameIfAvailable(ref ignore); - } - } - - internal abstract string InternalGetNameIfAvailable(ref Type rootCauseForFailure); - - internal abstract bool InternalIsMultiDimArray { get; } - internal abstract bool InternalIsOpen { get; } - } -} - - diff --git a/src/System.Private.Reflection.Core/src/System.Private.Reflection.Core.csproj b/src/System.Private.Reflection.Core/src/System.Private.Reflection.Core.csproj index 78a6d366460..12a2571d96f 100644 --- a/src/System.Private.Reflection.Core/src/System.Private.Reflection.Core.csproj +++ b/src/System.Private.Reflection.Core/src/System.Private.Reflection.Core.csproj @@ -113,7 +113,6 @@ - @@ -128,9 +127,6 @@ - - - diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs index 2f3ed3965a3..f1978ed0143 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/Helpers.cs @@ -36,19 +36,6 @@ public static Type[] CloneTypeArray(this Type[] types) return clonedTypes; } - // TODO https://github.com/dotnet/corefx/issues/9805: This overload can and should be deleted once TypeInfo derives from Type again. - public static Type[] CloneTypeArray(this TypeInfo[] types) - { - if (types.Length == 0) - return Array.Empty(); - Type[] clonedTypes = new Type[types.Length]; - for (int i = 0; i < types.Length; i++) - { - clonedTypes[i] = types[i].AsType(); - } - return clonedTypes; - } - public static bool IsRuntimeImplemented(this Type type) { return type is IRuntimeImplementedType; @@ -73,27 +60,13 @@ public static string LastResortString(this RuntimeTypeHandle typeHandle) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeNamedTypeInfo CastToRuntimeNamedTypeInfo(this Type type) { - Debug.Assert(type != null); - TypeInfo typeInfo = type.GetTypeInfo(); - Debug.Assert(typeInfo is RuntimeNamedTypeInfo); - return (RuntimeNamedTypeInfo)typeInfo; + Debug.Assert(type is RuntimeNamedTypeInfo); + return (RuntimeNamedTypeInfo)type; } - // TODO https://github.com/dotnet/corefx/issues/9805: Once TypeInfo and Type are the same instance, this implementation should just cast and not call GetTypeInfo(). [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo CastToRuntimeTypeInfo(this Type type) { - Debug.Assert(type != null); - TypeInfo typeInfo = type.GetTypeInfo(); - Debug.Assert(typeInfo is RuntimeTypeInfo); - return (RuntimeTypeInfo)typeInfo; - } - - // TODO https://github.com/dotnet/corefx/issues/9805: Once TypeInfo and Type are the same instance, this overload should away. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RuntimeTypeInfo CastToRuntimeTypeInfo(this TypeInfo type) - { - Debug.Assert(type != null); Debug.Assert(type is RuntimeTypeInfo); return (RuntimeTypeInfo)type; } @@ -102,7 +75,7 @@ public static RuntimeTypeInfo CastToRuntimeTypeInfo(this TypeInfo type) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Type CastToType(this TypeInfo typeInfo) { - return typeInfo == null ? null : typeInfo.AsType(); + return typeInfo; } } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs index 57644f57f43..2ca3a6f9038 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs @@ -22,9 +22,6 @@ using Internal.Metadata.NativeFormat; using IRuntimeImplementedType = Internal.Reflection.Core.NonPortable.IRuntimeImplementedType; -using RuntimeType = Internal.Reflection.Core.NonPortable.RuntimeType; -using RuntimeTypeTemporary = System.Reflection.Runtime.Types.RuntimeTypeTemporary; - namespace System.Reflection.Runtime.TypeInfos { @@ -48,7 +45,6 @@ internal abstract partial class RuntimeTypeInfo : ExtensibleTypeInfo, ITraceable { protected RuntimeTypeInfo() { - _legacyAsType = new RuntimeTypeTemporary(this); } public abstract override Assembly Assembly { get; } @@ -72,7 +68,7 @@ public sealed override string AssemblyQualifiedName public sealed override Type AsType() { - return _legacyAsType; + return this; } public abstract override TypeAttributes Attributes { get; } @@ -260,14 +256,7 @@ public override MethodBase DeclaringMethod // public sealed override bool Equals(object obj) { - if (object.ReferenceEquals(this, obj)) - return true; - - // TODO https://github.com/dotnet/corefx/issues/9805: This makes Equals() act as if Type and TypeInfo are already the same instance. This extra check will go away once they actually are the same instance. - if (obj is RuntimeType && object.ReferenceEquals(_legacyAsType, obj)) - return true; - - return false; + return object.ReferenceEquals(this, obj); } public sealed override int GetHashCode() @@ -487,12 +476,10 @@ public sealed override bool IsAssignableFrom(TypeInfo typeInfo) return Assignability.IsAssignableFrom(this, typeInfo, ReflectionCoreExecution.ExecutionDomain.FoundationTypes); } - // - // TODO https://github.com/dotnet/corefx/issues/9805: Once the type hierarchy is switched over, must replace "virtual" with "override". // // Left unsealed as constructed generic types must override. // - public virtual bool IsConstructedGenericType + public override bool IsConstructedGenericType { get { @@ -711,10 +698,7 @@ public sealed override string Name public abstract override string ToString(); - // - // TODO https://github.com/dotnet/corefx/issues/9805: Once the type hierarchy is switched over, must add "sealed override". - // - public RuntimeTypeHandle TypeHandle + public sealed override RuntimeTypeHandle TypeHandle { get { @@ -742,20 +726,26 @@ public RuntimeTypeHandle TypeHandle protected abstract int InternalGetHashCode(); - // TODO https://github.com/dotnet/corefx/issues/9805: Once IsArrayImpl() is added back to System.Type, this method will need an "override" keyword. - protected virtual bool IsArrayImpl() + // + // Left unsealed since array types must override. + // + protected override bool IsArrayImpl() { return false; } - // TODO https://github.com/dotnet/corefx/issues/9805: Once IsByRefImpl() is added back to System.Type, this method will need an "override" keyword. - protected virtual bool IsByRefImpl() + // + // Left unsealed since byref types must override. + // + protected override bool IsByRefImpl() { return false; } - // TODO https://github.com/dotnet/corefx/issues/9805: Once IsPointerImpl() is added back to System.Type, this method will need an "override" keyword. - protected virtual bool IsPointerImpl() + // + // Left unsealed since pointer types must override. + // + protected override bool IsPointerImpl() { return false; } @@ -1199,9 +1189,6 @@ private TypeInfoCachedData TypeInfoCachedData private volatile TypeInfoCachedData _lazyTypeInfoCachedData; private String _debugName; - - // TODO https://github.com/dotnet/corefx/issues/9805: This will go away once Type and TypeInfo are the same object. - private readonly RuntimeType _legacyAsType; } } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Types/RuntimeTypeTemporary.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Types/RuntimeTypeTemporary.cs deleted file mode 100644 index a5a789217d4..00000000000 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/Types/RuntimeTypeTemporary.cs +++ /dev/null @@ -1,108 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Reflection; -using System.Diagnostics; -using System.Reflection.Runtime.General; -using System.Reflection.Runtime.TypeInfos; - -using RuntimeType = Internal.Reflection.Core.NonPortable.RuntimeType; - -namespace System.Reflection.Runtime.Types -{ - // - // TODO https://github.com/dotnet/corefx/issues/9805: - // - // This is the only remaining non-abstract RuntimeType class. All RuntimeTypeInfo objects create one of these as their "AsType()" value. - // As its name implies, this type will go away entirely once Type's and TypeInfo's become the same instance object. - // - internal sealed class RuntimeTypeTemporary : RuntimeType - { - public RuntimeTypeTemporary(RuntimeTypeInfo typeInfo) - : base() - { - _typeInfo = typeInfo; - } - - public sealed override TypeInfo GetTypeInfo() => _typeInfo; - - // - // RuntimeTypeInfo's are unified using weak pointers so they use object.ReferenceEquals() for equality, and - // a type-specific hash code (to maintain a stable hash code across weak destructions and rebirths.) - // - // RuntimeTypeTemporaries are created and destroyed at the same time as the associated RuntimeTypeInfo object - // so they can use the same strategy: object.ReferenceEquals() for equality, and reuse the typeinfo's hash code. - // - public sealed override bool Equals(object obj) - { - if (object.ReferenceEquals(this, obj)) - return true; - - // TODO https://github.com/dotnet/corefx/issues/9805: This makes Equals() act as if Type and TypeInfo are already the same instance. This extra check will go away once they actually are the same instance. - if (obj is RuntimeTypeInfo && object.ReferenceEquals(this, ((RuntimeTypeInfo)obj).AsType())) - return true; - - return false; - } - - public sealed override int GetHashCode() => _typeInfo.GetHashCode(); - - public sealed override string AssemblyQualifiedName => _typeInfo.AssemblyQualifiedName; - public sealed override Type DeclaringType => _typeInfo.DeclaringType; - public sealed override string FullName => _typeInfo.FullName; - public sealed override int GenericParameterPosition => _typeInfo.GenericParameterPosition; - public sealed override Type[] GenericTypeArguments => _typeInfo.GenericTypeArguments; - public sealed override string Namespace => _typeInfo.Namespace; - - // - // TODO https://github.com/dotnet/corefx/issues/9805: - // Hack: We cannot call _typeInfo.IsArray because TypeInfo.IsArray is non-virtual and hard-coded to call AsType().IsArray (thus, infinite recursion.) - // We need to add back Type.IsArrayImpl() and change IsArray to call that. But that's being done in parallel with this work so I don't want to make that change now. - public sealed override bool IsArray => _typeInfo is RuntimeArrayTypeInfo; - public sealed override bool IsByRef => _typeInfo is RuntimeByRefTypeInfo; - public sealed override bool IsPointer => _typeInfo is RuntimePointerTypeInfo; - - public sealed override bool IsConstructedGenericType => _typeInfo.IsConstructedGenericType; - public sealed override bool IsGenericParameter => _typeInfo.IsGenericParameter; - - public sealed override int GetArrayRank() => _typeInfo.GetArrayRank(); - public sealed override Type GetElementType() => _typeInfo.GetElementType(); - public sealed override Type GetGenericTypeDefinition() => _typeInfo.GetGenericTypeDefinition(); - - public sealed override Type MakeArrayType() => _typeInfo.MakeArrayType(); - public sealed override Type MakeArrayType(int rank) => _typeInfo.MakeArrayType(rank); - public sealed override Type MakeByRefType() => _typeInfo.MakeByRefType(); - public sealed override Type MakeGenericType(params Type[] instantiation) => _typeInfo.MakeGenericType(instantiation); - public sealed override Type MakePointerType() => _typeInfo.MakePointerType(); - - public sealed override string Name => _typeInfo.Name; - public sealed override RuntimeTypeHandle TypeHandle => _typeInfo.TypeHandle; - public sealed override string ToString() => _typeInfo.ToString(); - - internal sealed override string InternalFullNameOfAssembly => _typeInfo.InternalFullNameOfAssembly; - internal sealed override bool InternalTryGetTypeHandle(out RuntimeTypeHandle typeHandle) - { - typeHandle = _typeInfo.InternalTypeHandleIfAvailable; - return !typeHandle.IsNull(); - } - - internal sealed override bool InternalIsGenericTypeDefinition => _typeInfo.IsGenericTypeDefinition; - internal sealed override RuntimeTypeInfo InternalRuntimeElementType => _typeInfo.InternalRuntimeElementType; - internal sealed override RuntimeTypeInfo[] InternalRuntimeGenericTypeArguments => _typeInfo.InternalRuntimeGenericTypeArguments; - internal sealed override string InternalGetNameIfAvailable(ref Type rootCauseForFailure) => _typeInfo.InternalGetNameIfAvailable(ref rootCauseForFailure); - - internal sealed override bool InternalIsMultiDimArray - { - get - { - return _typeInfo.InternalIsMultiDimArray; - } - } - - internal sealed override bool InternalIsOpen => _typeInfo.ContainsGenericParameters; - - private readonly RuntimeTypeInfo _typeInfo; - } -} diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/ConstraintValidatorSupport.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/ConstraintValidatorSupport.cs index bee531c8a4d..2fe05b9aad4 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/ConstraintValidatorSupport.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/TypeLoader/ConstraintValidatorSupport.cs @@ -33,73 +33,11 @@ public SigTypeContext(TypeInfo[] typeInstantiation, TypeInfo[] methodInstantiati } } - private class InstantiatedType : ExtensibleType, IReflectableType - { - private InstantiatedTypeInfo _typeInfo; - - public InstantiatedType(InstantiatedTypeInfo typeInfo) - { - _typeInfo = typeInfo; - } - - TypeInfo IReflectableType.GetTypeInfo() - { - return _typeInfo; - } - - // - // These methods can't be overriden on TypeInfo directly - // - public override bool IsArray - { - get - { - return _typeInfo.UnderlyingTypeInfo.IsArray; - } - } - - public override bool IsByRef - { - get - { - return _typeInfo.UnderlyingTypeInfo.IsByRef; - } - } - - public override bool IsPointer - { - get - { - return _typeInfo.UnderlyingTypeInfo.IsPointer; - } - } - - public override String AssemblyQualifiedName { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override String FullName { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override int GenericParameterPosition { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override Type[] GenericTypeArguments { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override bool IsConstructedGenericType { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override bool IsGenericParameter { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override int GetArrayRank() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type GetElementType() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type GetGenericTypeDefinition() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type MakeArrayType() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type MakeArrayType(int rank) { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type MakeByRefType() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type MakeGenericType(params Type[] instantiation) { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type MakePointerType() { Debug.Assert(false); throw NotImplemented.ByDesign; } - public override Type DeclaringType { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override string Namespace { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - public override String Name { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } - } - private class InstantiatedTypeInfo : ExtensibleTypeInfo { private TypeInfo _underlyingTypeInfo; private SigTypeContext _context; - private InstantiatedType _type; - public InstantiatedTypeInfo(TypeInfo underlyingTypeInfo, SigTypeContext context) { _underlyingTypeInfo = underlyingTypeInfo; @@ -116,9 +54,7 @@ public TypeInfo UnderlyingTypeInfo public override Type AsType() { - if (_type == null) - _type = new InstantiatedType(this); - return _type; + return this; } public override TypeAttributes Attributes @@ -140,6 +76,14 @@ public override IEnumerable ImplementedInterfaces } } + public override bool IsConstructedGenericType + { + get + { + return _underlyingTypeInfo.IsConstructedGenericType; + } + } + public override bool IsValueType { get @@ -215,6 +159,21 @@ public override Type BaseType public sealed override Type MakePointerType() { Debug.Assert(false); throw NotImplemented.ByDesign; } public override Type DeclaringType { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } public sealed override String Name { get { Debug.Assert(false); throw NotImplemented.ByDesign; } } + + protected override bool IsArrayImpl() + { + return _underlyingTypeInfo.IsArray; + } + + protected override bool IsByRefImpl() + { + return _underlyingTypeInfo.IsByRef; + } + + protected override bool IsPointerImpl() + { + return _underlyingTypeInfo.IsPointer; + } } private static TypeInfo Instantiate(this TypeInfo type, SigTypeContext context)