From ff2455e3bc3bf39301b71eea234f11c5d56b395d Mon Sep 17 00:00:00 2001 From: Atsushi Kanamori Date: Wed, 3 May 2017 06:40:42 -0700 Subject: [PATCH] Implement Type.IsTypeDefinition property on CoreCLR (#11355) This api was just approved. https://github.com/dotnet/corefx/issues/17345 --- src/mscorlib/shared/System/Reflection/TypeDelegator.cs | 1 + src/mscorlib/shared/System/Type.cs | 1 + src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs | 2 ++ .../Reflection/Emit/GenericTypeParameterBuilder.cs | 2 ++ src/mscorlib/src/System/Reflection/Emit/SymbolType.cs | 3 +++ src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs | 2 ++ .../System/Reflection/Emit/TypeBuilderInstantiation.cs | 1 + src/mscorlib/src/System/RtType.cs | 5 +++++ src/mscorlib/src/System/RuntimeHandles.cs | 18 ++++++++++++++++++ 9 files changed, 35 insertions(+) diff --git a/src/mscorlib/shared/System/Reflection/TypeDelegator.cs b/src/mscorlib/shared/System/Reflection/TypeDelegator.cs index 7f928d24..a301ddc 100644 --- a/src/mscorlib/shared/System/Reflection/TypeDelegator.cs +++ b/src/mscorlib/shared/System/Reflection/TypeDelegator.cs @@ -100,6 +100,7 @@ namespace System.Reflection protected override TypeAttributes GetAttributeFlagsImpl() => typeImpl.Attributes; + public override bool IsTypeDefinition => typeImpl.IsTypeDefinition; public override bool IsSZArray => typeImpl.IsSZArray; protected override bool IsArrayImpl() => typeImpl.IsArray; diff --git a/src/mscorlib/shared/System/Type.cs b/src/mscorlib/shared/System/Type.cs index 7749c17..2ba5891 100644 --- a/src/mscorlib/shared/System/Type.cs +++ b/src/mscorlib/shared/System/Type.cs @@ -32,6 +32,7 @@ namespace System public override Type ReflectedType => null; public abstract Type UnderlyingSystemType { get; } + public virtual bool IsTypeDefinition { get { throw NotImplemented.ByDesign; } } public bool IsArray => IsArrayImpl(); protected abstract bool IsArrayImpl(); public bool IsByRef => IsByRefImpl(); diff --git a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs index 55aa5c5..a36882b 100644 --- a/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs @@ -242,6 +242,8 @@ namespace System.Reflection.Emit return m_typeBuilder.Attributes; } + public override bool IsTypeDefinition => true; + public override bool IsSZArray => false; protected override bool IsArrayImpl() diff --git a/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs index dd5ffa9..75e4acc 100644 --- a/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs @@ -154,6 +154,8 @@ namespace System.Reflection.Emit protected override TypeAttributes GetAttributeFlagsImpl() { return TypeAttributes.Public; } + public override bool IsTypeDefinition => false; + public override bool IsSZArray => false; protected override bool IsArrayImpl() { return false; } diff --git a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs index 16848b4..58d5a17 100644 --- a/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs +++ b/src/mscorlib/src/System/Reflection/Emit/SymbolType.cs @@ -271,6 +271,9 @@ namespace System.Reflection.Emit #endregion #region Type Overrides + + public override bool IsTypeDefinition => false; + public override bool IsSZArray => m_cRank <= 1 && m_isSzArray; public override Type MakePointerType() diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs index a98af2b..5ccbf34 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs @@ -1109,6 +1109,8 @@ namespace System.Reflection.Emit return m_iAttr; } + public override bool IsTypeDefinition => true; + public override bool IsSZArray => false; protected override bool IsArrayImpl() diff --git a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs index 6d46362..64a38b0 100644 --- a/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs +++ b/src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs @@ -189,6 +189,7 @@ namespace System.Reflection.Emit public override MemberInfo[] GetMembers(BindingFlags bindingAttr) { throw new NotSupportedException(); } protected override TypeAttributes GetAttributeFlagsImpl() { return m_type.Attributes; } + public override bool IsTypeDefinition => false; public override bool IsSZArray => false; protected override bool IsArrayImpl() { return false; } diff --git a/src/mscorlib/src/System/RtType.cs b/src/mscorlib/src/System/RtType.cs index ef3ba29..6d0aa6f 100644 --- a/src/mscorlib/src/System/RtType.cs +++ b/src/mscorlib/src/System/RtType.cs @@ -3792,6 +3792,11 @@ namespace System #endregion #region Misc + public override bool IsTypeDefinition + { + get { return RuntimeTypeHandle.IsTypeDefinition(this); } + } + public override Type MakePointerType() { return new RuntimeTypeHandle(this).MakePointer(); } public override Type MakeByRefType() { return new RuntimeTypeHandle(this).MakeByRef(); } public override Type MakeArrayType() { return new RuntimeTypeHandle(this).MakeSZArray(); } diff --git a/src/mscorlib/src/System/RuntimeHandles.cs b/src/mscorlib/src/System/RuntimeHandles.cs index ab125e7..fd32547 100644 --- a/src/mscorlib/src/System/RuntimeHandles.cs +++ b/src/mscorlib/src/System/RuntimeHandles.cs @@ -127,6 +127,24 @@ namespace System m_type = type; } + internal static bool IsTypeDefinition(RuntimeType type) + { + CorElementType corElemType = GetCorElementType(type); + if (!((corElemType >= CorElementType.Void && corElemType < CorElementType.Ptr) || + corElemType == CorElementType.ValueType || + corElemType == CorElementType.Class || + corElemType == CorElementType.TypedByRef || + corElemType == CorElementType.I || + corElemType == CorElementType.U || + corElemType == CorElementType.Object)) + return false; + + if (HasInstantiation(type) && !IsGenericTypeDefinition(type)) + return false; + + return true; + } + internal static bool IsPrimitive(RuntimeType type) { CorElementType corElemType = GetCorElementType(type); -- 2.7.4