diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index 88113f771b7e41..5e872581a02f60 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -3568,18 +3568,18 @@ public override Type[] GetGenericArguments() } [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] - public override Type MakeGenericType(Type[] instantiation) + public override Type MakeGenericType(Type[] typeArguments) { - ArgumentNullException.ThrowIfNull(instantiation); + ArgumentNullException.ThrowIfNull(typeArguments); if (!IsGenericTypeDefinition) throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); RuntimeType[] genericParameters = GetGenericArgumentsInternal(); - if (genericParameters.Length != instantiation.Length) - throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(instantiation)); + if (genericParameters.Length != typeArguments.Length) + throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(typeArguments)); - if (instantiation.Length == 1 && instantiation[0] is RuntimeType rt) + if (typeArguments.Length == 1 && typeArguments[0] is RuntimeType rt) { ThrowIfTypeNeverValidGenericArgument(rt); try @@ -3593,13 +3593,13 @@ public override Type MakeGenericType(Type[] instantiation) } } - RuntimeType[] instantiationRuntimeType = new RuntimeType[instantiation.Length]; + RuntimeType[] instantiationRuntimeType = new RuntimeType[typeArguments.Length]; bool foundSigType = false; bool foundNonRuntimeType = false; - for (int i = 0; i < instantiation.Length; i++) + for (int i = 0; i < typeArguments.Length; i++) { - Type instantiationElem = instantiation[i] ?? throw new ArgumentNullException(); + Type instantiationElem = typeArguments[i] ?? throw new ArgumentNullException(); RuntimeType? rtInstantiationElem = instantiationElem as RuntimeType; if (rtInstantiationElem == null) @@ -3617,9 +3617,9 @@ public override Type MakeGenericType(Type[] instantiation) if (foundNonRuntimeType) { if (foundSigType) - return new SignatureConstructedGenericType(this, instantiation); + return new SignatureConstructedGenericType(this, typeArguments); - return Reflection.Emit.TypeBuilderInstantiation.MakeGenericType(this, (Type[])(instantiation.Clone())); + return Reflection.Emit.TypeBuilderInstantiation.MakeGenericType(this, (Type[])(typeArguments.Clone())); } SanityCheckGenericArguments(instantiationRuntimeType, genericParameters); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs index 45d5f50c528fc3..152a4b6cef8867 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureConstructedGenericType.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics; using System.Text; namespace System.Reflection @@ -11,8 +12,9 @@ internal sealed class SignatureConstructedGenericType : SignatureType // intended user of this constructor. internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] typeArguments) { - ArgumentNullException.ThrowIfNull(genericTypeDefinition); - ArgumentNullException.ThrowIfNull(typeArguments); + Debug.Assert(genericTypeDefinition != null); + Debug.Assert(typeArguments != null); + Debug.Assert(genericTypeDefinition.IsGenericTypeDefinition); typeArguments = (Type[])(typeArguments.Clone()); for (int i = 0; i < typeArguments.Length; i++) @@ -30,6 +32,7 @@ internal SignatureConstructedGenericType(Type genericTypeDefinition, Type[] type protected sealed override bool IsArrayImpl() => false; protected sealed override bool IsByRefImpl() => false; public sealed override bool IsByRefLike => _genericTypeDefinition.IsByRefLike; + public sealed override bool IsEnum => _genericTypeDefinition.IsEnum; protected sealed override bool IsPointerImpl() => false; public sealed override bool IsSZArray => false; public sealed override bool IsVariableBoundArray => false; @@ -50,6 +53,7 @@ public sealed override bool ContainsGenericParameters } } + protected sealed override bool IsValueTypeImpl() => _genericTypeDefinition.IsValueType; internal sealed override SignatureType? ElementType => null; public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass); public sealed override Type GetGenericTypeDefinition() => _genericTypeDefinition; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs index 447f40eb917df3..7bd1df5bca35f9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureGenericParameterType.cs @@ -19,6 +19,7 @@ protected SignatureGenericParameterType(int position) protected sealed override bool IsArrayImpl() => false; protected sealed override bool IsByRefImpl() => false; public sealed override bool IsByRefLike => false; + public sealed override bool IsEnum => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override bool IsPointerImpl() => false; public sealed override bool IsSZArray => false; public sealed override bool IsVariableBoundArray => false; @@ -26,6 +27,7 @@ protected SignatureGenericParameterType(int position) public sealed override bool IsGenericParameter => true; public abstract override bool IsGenericMethodParameter { get; } public sealed override bool ContainsGenericParameters => true; + protected sealed override bool IsValueTypeImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); internal sealed override SignatureType? ElementType => null; public sealed override int GetArrayRank() => throw new ArgumentException(SR.Argument_HasToBeArrayClass); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs index 694087149ee479..664a3301f1a902 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureHasElementType.cs @@ -19,6 +19,7 @@ protected SignatureHasElementType(SignatureType elementType) protected abstract override bool IsArrayImpl(); protected abstract override bool IsByRefImpl(); public sealed override bool IsByRefLike => false; + public sealed override bool IsEnum => false; protected abstract override bool IsPointerImpl(); public abstract override bool IsSZArray { get; } public abstract override bool IsVariableBoundArray { get; } @@ -27,6 +28,7 @@ protected SignatureHasElementType(SignatureType elementType) public sealed override bool IsGenericTypeParameter => false; public sealed override bool IsGenericMethodParameter => false; public sealed override bool ContainsGenericParameters => _elementType.ContainsGenericParameters; + protected sealed override bool IsValueTypeImpl() => false; internal sealed override SignatureType? ElementType => _elementType; public abstract override int GetArrayRank(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs index 15f791fddff16d..90832ed5f1711b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/SignatureType.cs @@ -188,7 +188,7 @@ public sealed override Type MakeArrayType(int rank) public sealed override Type[] FindInterfaces(TypeFilter filter, object? filterCriteria) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] Type interfaceType) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override bool IsContextfulImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); - public sealed override bool IsEnum => throw new NotSupportedException(SR.NotSupported_SignatureType); + public abstract override bool IsEnum { get; } public sealed override bool IsEquivalentTo([NotNullWhen(true)] Type? other) => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override bool IsInstanceOfType([NotNullWhen(true)] object? o) => throw new NotSupportedException(SR.NotSupported_SignatureType); protected sealed override bool IsMarshalByRefImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); @@ -198,7 +198,7 @@ public sealed override Type MakeArrayType(int rank) [Obsolete(Obsoletions.LegacyFormatterMessage, DiagnosticId = Obsoletions.LegacyFormatterDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public sealed override bool IsSerializable => throw new NotSupportedException(SR.NotSupported_SignatureType); public sealed override bool IsSubclassOf(Type c) => throw new NotSupportedException(SR.NotSupported_SignatureType); - protected sealed override bool IsValueTypeImpl() => throw new NotSupportedException(SR.NotSupported_SignatureType); + protected abstract override bool IsValueTypeImpl(); public sealed override StructLayoutAttribute StructLayoutAttribute => throw new NotSupportedException(SR.NotSupported_SignatureType); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs index 33baea81496203..d0ab8d07203f38 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/TypeDelegator.cs @@ -57,6 +57,8 @@ public TypeDelegator([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes. public override string? AssemblyQualifiedName => typeImpl.AssemblyQualifiedName; public override Type? BaseType => typeImpl.BaseType; + public override int GetArrayRank() => typeImpl.GetArrayRank(); + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] protected override ConstructorInfo? GetConstructorImpl(BindingFlags bindingAttr, Binder? binder, CallingConventions callConvention, Type[] types, ParameterModifier[]? modifiers) diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 6947b0e5f04981..e00bcec7081d2b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -651,7 +651,16 @@ public virtual Array GetEnumValues() public virtual Type MakePointerType() => throw new NotSupportedException(); - public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments) => new SignatureConstructedGenericType(genericTypeDefinition, typeArguments); + public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments) + { + ArgumentNullException.ThrowIfNull(genericTypeDefinition); + ArgumentNullException.ThrowIfNull(typeArguments); + + if (!genericTypeDefinition.IsGenericTypeDefinition) + throw new ArgumentException(SR.Format(SR.Arg_NotGenericTypeDefinition, genericTypeDefinition), nameof(genericTypeDefinition)); + + return new SignatureConstructedGenericType(genericTypeDefinition, typeArguments); + } public static Type MakeGenericMethodParameter(int position) { diff --git a/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs b/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs index f508da07364f26..b052a2861961b6 100644 --- a/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs +++ b/src/libraries/System.Reflection.Emit/tests/PersistedAssemblyBuilder/AssemblySaveTypeBuilderTests.cs @@ -733,8 +733,6 @@ public void MethodBuilderGetParametersReturnParameterTest() Assert.True(method3.ReturnParameter.IsRetval); } - public class BaseType { } - [Fact] public void GenericTypeWithTypeBuilderGenericParameter_UsedAsParent() { @@ -749,9 +747,53 @@ public void GenericTypeWithTypeBuilderGenericParameter_UsedAsParent() Assert.NotNull(type.GetConstructor(Type.EmptyTypes)); // Default constructor created } + + [Fact] + public void CreateGenericTypeFromMetadataLoadContextSignatureTypes() + { + using TempFile file = TempFile.Create(); + + PersistedAssemblyBuilder ab = AssemblySaveTools.PopulateAssemblyAndModule(out ModuleBuilder module); + + TypeBuilder childType = module.DefineType("Child"); + TypeBuilder parentType = module.DefineType("Parent"); + + // Get List from MLC and make both reference and value type fields from that. + using MetadataLoadContext mlc = new MetadataLoadContext(new CoreMetadataAssemblyResolver()); + Type listOfTType = mlc.CoreAssembly.GetType(typeof(List<>).FullName!); + + // Currently MakeGenericSignatureType() must be used instead of MakeGenericType() for + // generic type parameters created with TypeBuilder. + Assert.Throws(() => listOfTType.MakeGenericType(childType)); + Type listOfReferenceTypes = Type.MakeGenericSignatureType(listOfTType, childType); + parentType.DefineField("ReferenceTypeChildren", listOfReferenceTypes, FieldAttributes.Public); + + // Pre-existing types can use MakeGenericType(). + Type int32Type = mlc.CoreAssembly.GetType(typeof(int).FullName); + Type listOfValueTypes = listOfTType.MakeGenericType(int32Type); + parentType.DefineField("ValueTypeChildren", listOfValueTypes, FieldAttributes.Public); + + parentType.CreateType(); + childType.CreateType(); + + // Save and load the dynamically created assembly. + ab.Save(file.Path); + Module mlcModule = mlc.LoadFromAssemblyPath(file.Path).Modules.First(); + + Assert.Equal("Child", mlcModule.GetTypes()[0].Name); + Assert.Equal("Parent", mlcModule.GetTypes()[1].Name); + + FieldInfo[] fields = mlcModule.GetTypes()[1].GetFields(BindingFlags.Public | BindingFlags.Instance); + Assert.Equal("ReferenceTypeChildren", fields[0].Name); + Assert.False(fields[0].FieldType.GetGenericArguments()[0].IsValueType); + Assert.Equal("ValueTypeChildren", fields[1].Name); + Assert.True(fields[1].FieldType.GetGenericArguments()[0].IsValueType); + } } // Test Types + public class BaseType { } + public interface INoMethod { } diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs index c31971a89f66b4..2c346f23e05796 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/SignatureTypes.cs @@ -10,24 +10,18 @@ namespace System.Reflection.Tests { public static class SignatureTypeTests { - [Fact] - public static void IsSignatureType() + [Theory] + [MemberData(nameof(IsSignatureTypeTestData))] + public static void IsSignatureType(Type type, bool expected) { - // Executing [Theory] logic manually. Signature Types cannot be used in theory data because Xunit preemptively invokes an unguarded - // System.Type pretty printer that invokes members that Signature Types don't support. - foreach (object[] pair in IsSignatureTypeTestData) - { - Type type = (Type)(pair[0]); - bool expected = (bool)(pair[1]); - - Assert.Equal(expected, type.IsSignatureType); - } + Assert.Equal(expected, type.IsSignatureType); } public static IEnumerable IsSignatureTypeTestData { get { + // Standard reflection used as baseline. yield return new object[] { typeof(int), false }; yield return new object[] { typeof(int).MakeArrayType(), false }; yield return new object[] { typeof(int).MakeArrayType(1), false }; @@ -37,6 +31,7 @@ public static IEnumerable IsSignatureTypeTestData yield return new object[] { typeof(List<>).MakeGenericType(typeof(int)), false }; yield return new object[] { typeof(List<>).GetGenericArguments()[0], false }; + // SignatureTypes. Type sigType = Type.MakeGenericMethodParameter(2); yield return new object[] { sigType, true }; @@ -48,7 +43,9 @@ public static IEnumerable IsSignatureTypeTestData yield return new object[] { typeof(List<>).MakeGenericType(sigType), true }; yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), typeof(int)), true }; + yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), typeof(int)).GetGenericArguments()[0], false }; yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), sigType), true }; + yield return new object[] { Type.MakeGenericSignatureType(typeof(List<>), sigType).GetGenericArguments()[0], true }; } } @@ -211,6 +208,8 @@ public static void MakeGenericMethodParameter(int position) Assert.False(t.IsGenericTypeParameter); Assert.True(t.IsGenericMethodParameter); Assert.Equal(position, t.GenericParameterPosition); + Assert.Throws(() => t.IsValueType); + Assert.Throws(() => t.IsEnum); TestSignatureTypeInvariants(t); } @@ -231,6 +230,8 @@ public static void MakeSignatureArrayType() Assert.True(t.IsArray); Assert.True(t.IsSZArray); Assert.Equal(1, t.GetArrayRank()); + Assert.False(t.IsValueType); + Assert.False(t.IsEnum); Type et = t.GetElementType(); Assert.True(et.IsSignatureType); @@ -253,6 +254,8 @@ public static void MakeSignatureMdArrayType(int rank) Assert.True(t.IsArray); Assert.True(t.IsVariableBoundArray); Assert.Equal(rank, t.GetArrayRank()); + Assert.False(t.IsValueType); + Assert.False(t.IsEnum); TestSignatureTypeInvariants(t); } @@ -263,6 +266,8 @@ public static void MakeSignatureByRefType() Type t = Type.MakeGenericMethodParameter(5); t = t.MakeByRefType(); Assert.True(t.IsByRef); + Assert.False(t.IsValueType); + Assert.False(t.IsEnum); Type et = t.GetElementType(); Assert.True(et.IsSignatureType); @@ -280,6 +285,8 @@ public static void MakeSignaturePointerType() Type t = Type.MakeGenericMethodParameter(5); t = t.MakePointerType(); Assert.True(t.IsPointer); + Assert.False(t.IsValueType); + Assert.False(t.IsEnum); Type et = t.GetElementType(); Assert.True(et.IsSignatureType); @@ -294,6 +301,7 @@ public static void MakeSignaturePointerType() [Theory] [InlineData(typeof(List<>))] [InlineData(typeof(Span<>))] + [InlineData(typeof(GenericType<>.GenericEnum))] public static void MakeSignatureConstructedGenericType(Type genericTypeDefinition) { Type gmp = Type.MakeGenericMethodParameter(5); @@ -305,6 +313,8 @@ public static void MakeSignatureConstructedGenericType(Type genericTypeDefinitio Assert.True(t.IsConstructedGenericType); Assert.Equal(genericTypeDefinition, t.GetGenericTypeDefinition()); Assert.Equal(1, t.GenericTypeArguments.Length); + Assert.Equal(genericTypeDefinition.IsValueType, t.IsValueType); + Assert.Equal(genericTypeDefinition.IsEnum, t.IsEnum); Type et = t.GenericTypeArguments[0]; Assert.True(et.IsSignatureType); @@ -320,9 +330,18 @@ public static void MakeSignatureConstructedGenericType(Type genericTypeDefinitio [Fact] public static void MakeGenericSignatureTypeValidation() { - AssertExtensions.Throws("genericTypeDefinition", () => Type.MakeGenericSignatureType(null)); - AssertExtensions.Throws("typeArguments", () => Type.MakeGenericSignatureType(typeof(IList<>), typeArguments: null)); - AssertExtensions.Throws("typeArguments", () => Type.MakeGenericSignatureType(typeof(IList<>), new Type[] { null })); + // Calls to MakeGenericSignatureType() should have consistent validation with MakeGenericType(). + + AssertExtensions.Throws("genericTypeDefinition", () => Type.MakeGenericSignatureType(genericTypeDefinition: null)); + + AssertExtensions.Throws("genericTypeDefinition", () => Type.MakeGenericSignatureType(genericTypeDefinition: typeof(int), typeArguments: new Type[] { typeof(int) })); + AssertExtensions.Throws(() => typeof(int).MakeGenericType(typeArguments: new Type[] { typeof(int) })); + + AssertExtensions.Throws("typeArguments", () => Type.MakeGenericSignatureType(genericTypeDefinition: typeof(IList<>), typeArguments: null)); + AssertExtensions.Throws("typeArguments", () => typeof(IList<>).MakeGenericType(typeArguments: null)); + + AssertExtensions.Throws(() => Type.MakeGenericSignatureType(genericTypeDefinition: typeof(IList<>), typeArguments: new Type[] { null })); + AssertExtensions.Throws(() => typeof(IList<>).MakeGenericType(typeArguments: new Type[] { null })); } private static Type ToSignatureType(this Type type) @@ -408,6 +427,13 @@ public static void Moo(int p1, int p2) where M : NoOneSubclassesThisEither { private class NoOneSubclasses { } private class NoOneSubclassesThisEither { } + private class GenericType + { + public enum GenericEnum + { + } + } + private static void TestSignatureTypeInvariants(Type type) { Assert.True(type.IsSignatureType); diff --git a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 348125a734fb26..9cc526de765f0b 100644 --- a/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -1413,23 +1413,23 @@ public override Type[] GetGenericArguments() } [RequiresUnreferencedCode("If some of the generic arguments are annotated (either with DynamicallyAccessedMembersAttribute, or generic constraints), trimming can't validate that the requirements of those annotations are met.")] - public override Type MakeGenericType(Type[] instantiation) + public override Type MakeGenericType(Type[] typeArguments) { - ArgumentNullException.ThrowIfNull(instantiation); + ArgumentNullException.ThrowIfNull(typeArguments); - RuntimeType[] instantiationRuntimeType = new RuntimeType[instantiation.Length]; + RuntimeType[] instantiationRuntimeType = new RuntimeType[typeArguments.Length]; if (!IsGenericTypeDefinition) throw new InvalidOperationException(SR.Format(SR.Arg_NotGenericTypeDefinition, this)); RuntimeType[] genericParameters = GetGenericArgumentsInternal(); - if (genericParameters.Length != instantiation.Length) - throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(instantiation)); + if (genericParameters.Length != typeArguments.Length) + throw new ArgumentException(SR.Argument_GenericArgsCount, nameof(typeArguments)); - for (int i = 0; i < instantiation.Length; i++) + for (int i = 0; i < typeArguments.Length; i++) { - Type instantiationElem = instantiation[i]; + Type instantiationElem = typeArguments[i]; if (instantiationElem == null) throw new ArgumentNullException(); @@ -1438,14 +1438,14 @@ public override Type MakeGenericType(Type[] instantiation) if (rtInstantiationElem == null) { if (instantiationElem.IsSignatureType) - return MakeGenericSignatureType(this, instantiation); - Type[] instantiationCopy = new Type[instantiation.Length]; - for (int iCopy = 0; iCopy < instantiation.Length; iCopy++) - instantiationCopy[iCopy] = instantiation[iCopy]; - instantiation = instantiationCopy; + return MakeGenericSignatureType(this, typeArguments); + Type[] instantiationCopy = new Type[typeArguments.Length]; + for (int iCopy = 0; iCopy < typeArguments.Length; iCopy++) + instantiationCopy[iCopy] = typeArguments[iCopy]; + typeArguments = instantiationCopy; if (!RuntimeFeature.IsDynamicCodeSupported) throw new PlatformNotSupportedException(); - return System.Reflection.Emit.TypeBuilderInstantiation.MakeGenericType(this, instantiation); + return System.Reflection.Emit.TypeBuilderInstantiation.MakeGenericType(this, typeArguments); } instantiationRuntimeType[i] = rtInstantiationElem;