Virtual AttributeType property and signature generic types (dotnet/coreclr#19818)
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Tue, 4 Sep 2018 18:24:00 +0000 (11:24 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Sep 2018 18:24:00 +0000 (11:24 -0700)
* Virtual AttributeType property and signature generic types

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

1. This will allow Reflection providers the option
to supply the attribute type without building
an entire constructor.

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

2. This will permit other Reflection providers
to support Type.MakeGenericMethodParameter()
in their implementations.

* More robust argument validation.

* Change parameter name

Commit migrated from https://github.com/dotnet/coreclr/commit/a1cb8f6e39ba93d21f2fc2bd0405b9d6d28b42ee

src/coreclr/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs
src/libraries/System.Private.CoreLib/src/System/Type.cs

index 767fadf..c1c6e4f 100644 (file)
@@ -500,7 +500,7 @@ namespace System.Reflection
         #endregion
 
         #region Public Members
-        public Type AttributeType { get { return Constructor.DeclaringType; } }
+        public virtual Type AttributeType { get { return Constructor.DeclaringType; } }
 
         public virtual ConstructorInfo Constructor { get { return m_ctor; } }
 
index cd97ffa..d3d8852 100644 (file)
@@ -10,11 +10,25 @@ namespace System.Reflection
 {
     internal sealed class SignatureConstructedGenericType : SignatureType
     {
-        internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] genericTypeArguments)
+        // The exception-visible name "typeArguments" is chosen to match the parameter name to Type.MakeGenericType() since that's the
+        // intended user of this constructor.
+        internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] typeArguments)
         {
-            Debug.Assert(genericTypeDefinition != null && genericTypeArguments != null);
+            if (genericTypeDefinition == null)
+                throw new ArgumentNullException(nameof(genericTypeDefinition));
+
+            if (typeArguments == null)
+                throw new ArgumentNullException(nameof(typeArguments));
+
+            typeArguments = (Type[])(typeArguments.Clone());
+            for (int i = 0; i < typeArguments.Length; i++)
+            {
+                if (typeArguments[i] == null)
+                    throw new ArgumentNullException(nameof(typeArguments));
+            }
+
             _genericTypeDefinition = genericTypeDefinition;
-            _genericTypeArguments = (Type[])(genericTypeArguments.Clone());
+            _genericTypeArguments = typeArguments;
         }
     
         public sealed override bool IsTypeDefinition => false;
index 79f6b6f..c78d988 100644 (file)
@@ -346,6 +346,8 @@ namespace System
         public virtual Type MakeGenericType(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); }
         public virtual Type MakePointerType() { throw new NotSupportedException(); }
 
+        public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments) => new SignatureConstructedGenericType(genericTypeDefinition, typeArguments);
+
         public static Type MakeGenericMethodParameter(int position)
         {
             if (position < 0)