diff options
author | Atsushi Kanamori <AtsushiKan@users.noreply.github.com> | 2017-10-04 01:22:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-04 01:22:38 +0300 |
commit | 672c543d12cc24f19ecdc55fe9338eefbb659777 (patch) | |
tree | 5285c3cad52d3e7459a2aec8ba905968231bef6b | |
parent | eabdf9f64ad5a29153c6a0d37389b3b333f6813c (diff) |
Implement IsGenericTypeParameter and IsGenericMethodParameter on CoreRT (#4662)
Api approved here:
https://github.com/dotnet/corefx/issues/23883
17 files changed, 39 insertions, 13 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs index afcdfda35..cd97ffa21 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureConstructedGenericType.cs @@ -28,6 +28,7 @@ namespace System.Reflection public sealed override bool IsVariableBoundArray => false; public sealed override bool IsConstructedGenericType => true; public sealed override bool IsGenericParameter => false; + public sealed override bool IsGenericTypeParameter => false; public sealed override bool IsGenericMethodParameter => false; public sealed override bool ContainsGenericParameters { diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs index ae73272ab..d0790283f 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureGenericMethodParameterType.cs @@ -10,7 +10,8 @@ namespace System.Reflection : base(position) { } - + + public sealed override bool IsGenericTypeParameter => false; public sealed override bool IsGenericMethodParameter => true; public sealed override string Name => "!!" + GenericParameterPosition; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs index e1aa6c358..e74e5f5aa 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureHasElementType.cs @@ -26,6 +26,7 @@ namespace System.Reflection public abstract override bool IsVariableBoundArray { get; } public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => false; + public sealed override bool IsGenericTypeParameter => false; public sealed override bool IsGenericMethodParameter => false; public sealed override bool ContainsGenericParameters => _elementType.ContainsGenericParameters; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs index c3dfc4917..40a059044 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureType.cs @@ -31,7 +31,8 @@ namespace System.Reflection public abstract override bool IsGenericTypeDefinition { get; } public abstract override bool IsConstructedGenericType { get; } public abstract override bool IsGenericParameter { get; } - public abstract bool IsGenericMethodParameter { get; } + public abstract override bool IsGenericTypeParameter { get; } + public abstract override bool IsGenericMethodParameter { get; } public abstract override bool ContainsGenericParameters { get; } public sealed override MemberTypes MemberType => MemberTypes.TypeInfo; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs index b30da5007..f0a33d0ba 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs @@ -84,7 +84,7 @@ namespace System.Reflection } else if (pattern.IsGenericMethodParameter) { - if (!(actual.IsGenericParameter && actual.DeclaringMethod != null)) + if (!actual.IsGenericMethodParameter) return false; if (pattern.GenericParameterPosition != actual.GenericParameterPosition) return false; diff --git a/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs b/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs index 1dba27889..ac3972fb7 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/TypeDelegator.cs @@ -105,6 +105,8 @@ namespace System.Reflection protected override bool IsArrayImpl() => typeImpl.IsArray; protected override bool IsPrimitiveImpl() => typeImpl.IsPrimitive; protected override bool IsByRefImpl() => typeImpl.IsByRef; + public override bool IsGenericTypeParameter => typeImpl.IsGenericTypeParameter; + public override bool IsGenericMethodParameter => typeImpl.IsGenericMethodParameter; protected override bool IsPointerImpl() => typeImpl.IsPointer; protected override bool IsValueTypeImpl() => typeImpl.IsValueType; protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject; diff --git a/src/System.Private.CoreLib/shared/System/Type.cs b/src/System.Private.CoreLib/shared/System/Type.cs index ab3d55bc6..6b6a7b376 100644 --- a/src/System.Private.CoreLib/shared/System/Type.cs +++ b/src/System.Private.CoreLib/shared/System/Type.cs @@ -41,6 +41,8 @@ namespace System protected abstract bool IsPointerImpl(); public virtual bool IsConstructedGenericType { get { throw NotImplemented.ByDesign; } } public virtual bool IsGenericParameter => false; + public virtual bool IsGenericTypeParameter => IsGenericParameter && DeclaringMethod == null; + public virtual bool IsGenericMethodParameter => IsGenericParameter && DeclaringMethod != null; public virtual bool IsGenericType => false; public virtual bool IsGenericTypeDefinition => false; diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs index d807aa383..62177be3f 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs @@ -172,19 +172,15 @@ namespace System.Reflection.Runtime.BindingFlagSupport return true; } - if (t1.IsGenericParameter && t2.IsGenericParameter) + if (t1.IsGenericMethodParameter && t2.IsGenericMethodParameter) { - if (t1.DeclaringMethod != null && t2.DeclaringMethod != null) - { - // A generic method parameter. The DeclaringMethods will be different but we don't care about that - we can assume that - // the declaring method will be the method that declared the parameter's whose type we're testing. We only need to - // compare the positions. - return t1.GenericParameterPosition == t2.GenericParameterPosition; - } - return false; + // A generic method parameter. The DeclaringMethods will be different but we don't care about that - we can assume that + // the declaring method will be the method that declared the parameter's whose type we're testing. We only need to + // compare the positions. + return t1.GenericParameterPosition == t2.GenericParameterPosition; } - // If we got here, either t1 and t2 are different flavors of types or they are both simple named types. + // If we got here, either t1 and t2 are different flavors of types or they are both simple named types or both generic type parameters. // Either way, we can trust Reflection's result here. return false; } diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForMethods.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForMethods.cs index ec58e970e..08f497311 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForMethods.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForMethods.cs @@ -27,6 +27,9 @@ namespace System.Reflection.Runtime.TypeInfos.EcmaFormat _declaringRuntimeNamedMethodInfo = declaringRuntimeNamedMethodInfo; } + public sealed override bool IsGenericTypeParameter => false; + public sealed override bool IsGenericMethodParameter => true; + public sealed override MethodBase DeclaringMethod { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForTypes.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForTypes.cs index 2f14f6e27..d4d540cd9 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForTypes.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/EcmaFormat/EcmaFormatRuntimeGenericParameterTypeInfoForTypes.cs @@ -23,6 +23,9 @@ namespace System.Reflection.Runtime.TypeInfos.EcmaFormat _declaringType = declaringType; } + public sealed override bool IsGenericTypeParameter => true; + public sealed override bool IsGenericMethodParameter => false; + public sealed override MethodBase DeclaringMethod { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForMethods.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForMethods.cs index f237f5565..42640f7af 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForMethods.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForMethods.cs @@ -27,6 +27,9 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat _declaringRuntimeNamedMethodInfo = declaringRuntimeNamedMethodInfo; } + public sealed override bool IsGenericTypeParameter => false; + public sealed override bool IsGenericMethodParameter => true; + public sealed override MethodBase DeclaringMethod { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForTypes.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForTypes.cs index 2cbe72943..3cc9ab957 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForTypes.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/NativeFormat/NativeFormatRuntimeGenericParameterTypeInfoForTypes.cs @@ -23,6 +23,9 @@ namespace System.Reflection.Runtime.TypeInfos.NativeFormat _declaringType = declaringType; } + public sealed override bool IsGenericTypeParameter => true; + public sealed override bool IsGenericMethodParameter => false; + public sealed override MethodBase DeclaringMethod { get diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs index e96e36238..9740554ec 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeConstructedGenericTypeInfo.cs @@ -39,6 +39,8 @@ namespace System.Reflection.Runtime.TypeInfos protected sealed override bool IsPointerImpl() => false; public sealed override bool IsConstructedGenericType => true; public sealed override bool IsGenericParameter => false; + public sealed override bool IsGenericTypeParameter => false; + public sealed override bool IsGenericMethodParameter => false; public sealed override bool IsByRefLike => GenericTypeDefinitionTypeInfo.IsByRefLike; // diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs index 241878768..c5cae14b4 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeGenericParameterTypeInfo.cs @@ -35,6 +35,8 @@ namespace System.Reflection.Runtime.TypeInfos protected sealed override bool IsPointerImpl() => false; public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => true; + public abstract override bool IsGenericTypeParameter { get; } + public abstract override bool IsGenericMethodParameter { get; } public sealed override bool IsByRefLike => false; public sealed override Assembly Assembly diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs index 88ee72d35..be466e7e4 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeHasElementTypeInfo.cs @@ -36,6 +36,8 @@ namespace System.Reflection.Runtime.TypeInfos protected abstract override bool IsPointerImpl(); public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => false; + public sealed override bool IsGenericTypeParameter => false; + public sealed override bool IsGenericMethodParameter => false; public sealed override bool IsByRefLike => false; // diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs index 5fc2676eb..d1d33416e 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeDefinitionTypeInfo.cs @@ -24,6 +24,8 @@ namespace System.Reflection.Runtime.TypeInfos protected sealed override bool IsPointerImpl() => false; public sealed override bool IsConstructedGenericType => false; public sealed override bool IsGenericParameter => false; + public sealed override bool IsGenericTypeParameter => false; + public sealed override bool IsGenericMethodParameter => false; public sealed override bool IsByRefLike { diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs index 1e3cd5be5..66f0850c1 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs @@ -51,6 +51,8 @@ namespace System.Reflection.Runtime.TypeInfos protected abstract override bool IsByRefImpl(); protected abstract override bool IsPointerImpl(); public abstract override bool IsGenericParameter { get; } + public abstract override bool IsGenericTypeParameter { get; } + public abstract override bool IsGenericMethodParameter { get; } public abstract override bool IsConstructedGenericType { get; } public abstract override bool IsByRefLike { get; } |