diff options
author | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2018-09-04 21:24:00 +0300 |
---|---|---|
committer | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2018-09-05 00:59:16 +0300 |
commit | bdd0b15d921a91b46b11a2279708152553ed860f (patch) | |
tree | 2d97546c1d9170c299a85a6cc7097a222b512244 | |
parent | 60a9b7c8c4b353d3c94fe89b2d5022365d778748 (diff) |
Virtual AttributeType property and signature generic types (#19818)
* 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
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs | 20 | ||||
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Type.cs | 2 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs index cd97ffa21..d3d88520f 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs @@ -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; diff --git a/src/System.Private.CoreLib/shared/System/Type.cs b/src/System.Private.CoreLib/shared/System/Type.cs index 79f6b6f2f..c78d98833 100644 --- a/src/System.Private.CoreLib/shared/System/Type.cs +++ b/src/System.Private.CoreLib/shared/System/Type.cs @@ -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) |