Implement Type.IsTypeDefinition property on CoreCLR (#11355)
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Wed, 3 May 2017 13:40:42 +0000 (06:40 -0700)
committerGitHub <noreply@github.com>
Wed, 3 May 2017 13:40:42 +0000 (06:40 -0700)
This api was just approved.

https://github.com/dotnet/corefx/issues/17345

src/mscorlib/shared/System/Reflection/TypeDelegator.cs
src/mscorlib/shared/System/Type.cs
src/mscorlib/src/System/Reflection/Emit/EnumBuilder.cs
src/mscorlib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs
src/mscorlib/src/System/Reflection/Emit/SymbolType.cs
src/mscorlib/src/System/Reflection/Emit/TypeBuilder.cs
src/mscorlib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
src/mscorlib/src/System/RtType.cs
src/mscorlib/src/System/RuntimeHandles.cs

index 7f928d2..a301ddc 100644 (file)
@@ -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;
index 7749c17..2ba5891 100644 (file)
@@ -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();
index 55aa5c5..a36882b 100644 (file)
@@ -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()
index dd5ffa9..75e4acc 100644 (file)
@@ -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; }
index 16848b4..58d5a17 100644 (file)
@@ -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()
index a98af2b..5ccbf34 100644 (file)
@@ -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()
index 6d46362..64a38b0 100644 (file)
@@ -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; }
index ef3ba29..6d0aa6f 100644 (file)
@@ -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(); }
index ab125e7..fd32547 100644 (file)
@@ -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);