Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public sealed override MethodBase BindToMethod(
for (i = 0; i < types.Length; i++)
{
realTypes[i] = types[i].UnderlyingSystemType;
if (!(IsImplementedByMetadataLoadContext(realTypes[i]) || realTypes[i].IsSignatureType()))
if (!(IsImplementedByMetadataLoadContext(realTypes[i]) || realTypes[i].IsSignatureType))
throw new ArgumentException(SR.Arg_MustBeType, nameof(types));
}
types = realTypes;
Expand Down Expand Up @@ -81,7 +81,7 @@ public sealed override MethodBase BindToMethod(
continue;

Type? type = types[j];
if (type.IsSignatureType())
if (type.IsSignatureType)
{
if (!(candidates[i] is MethodInfo methodInfo))
break;
Expand Down Expand Up @@ -427,7 +427,7 @@ private static int FindMostSpecificType(Type c1, Type c2, Type t)
if (c1 == c2)
return 0;

if (t.IsSignatureType())
if (t.IsSignatureType)
{
if (t.MatchesExactly(c1))
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static bool GenericMethodAwareAreParameterTypesEqual(Type t1, Type t2)

if ((t1.IsArray && t2.IsArray) || (t1.IsByRef && t2.IsByRef) || (t1.IsPointer && t2.IsPointer))
{
if (t1.IsSZArray() != t2.IsSZArray())
if (t1.IsSZArray != t2.IsSZArray)
return false;

if (t1.IsArray && (t1.GetArrayRank() != t2.GetArrayRank()))
Expand Down Expand Up @@ -169,7 +169,7 @@ private static bool GenericMethodAwareAreParameterTypesEqual(Type t1, Type t2)
return true;
}

if (t1.IsGenericMethodParameter() && t2.IsGenericMethodParameter())
if (t1.IsGenericMethodParameter && t2.IsGenericMethodParameter)
{
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class SignatureTypeExtensions
/// </summary>
public static bool MatchesParameterTypeExactly(this Type pattern, ParameterInfo parameter)
{
if (pattern.IsSignatureType())
if (pattern.IsSignatureType)
return pattern.MatchesExactly(parameter.ParameterType);
else
return pattern == (object)(parameter.ParameterType);
Expand All @@ -32,15 +32,15 @@ public static bool MatchesParameterTypeExactly(this Type pattern, ParameterInfo
/// </summary>
internal static bool MatchesExactly(this Type pattern, Type actual)
{
Debug.Assert(pattern.IsSignatureType());
Debug.Assert(pattern.IsSignatureType);

if (pattern.IsSZArray())
if (pattern.IsSZArray)
{
return actual.IsSZArray() && pattern.GetElementType()!.MatchesExactly(actual.GetElementType()!);
return actual.IsSZArray && pattern.GetElementType()!.MatchesExactly(actual.GetElementType()!);
}
else if (pattern.IsVariableBoundArray())
else if (pattern.IsVariableBoundArray)
{
return actual.IsVariableBoundArray() && pattern.GetArrayRank() == actual.GetArrayRank() && pattern.GetElementType()!.MatchesExactly(actual.GetElementType()!);
return actual.IsVariableBoundArray && pattern.GetArrayRank() == actual.GetArrayRank() && pattern.GetElementType()!.MatchesExactly(actual.GetElementType()!);
}
else if (pattern.IsByRef)
{
Expand All @@ -64,7 +64,7 @@ internal static bool MatchesExactly(this Type pattern, Type actual)
for (int i = 0; i < count; i++)
{
Type patternGenericTypeArgument = patternGenericTypeArguments[i];
if (patternGenericTypeArgument.IsSignatureType())
if (patternGenericTypeArgument.IsSignatureType)
{
if (!patternGenericTypeArgument.MatchesExactly(actualGenericTypeArguments[i]))
return false;
Expand All @@ -77,9 +77,9 @@ internal static bool MatchesExactly(this Type pattern, Type actual)
}
return true;
}
else if (pattern.IsGenericMethodParameter())
else if (pattern.IsGenericMethodParameter)
{
if (!actual.IsGenericMethodParameter())
if (!actual.IsGenericMethodParameter)
return false;
if (pattern.GenericParameterPosition != actual.GenericParameterPosition)
return false;
Expand All @@ -104,19 +104,19 @@ internal static bool MatchesExactly(this Type pattern, Type actual)
/// </summary>
internal static Type? TryResolveAgainstGenericMethod(this Type signatureType, MethodInfo genericMethod)
{
Debug.Assert(signatureType.IsSignatureType());
Debug.Assert(signatureType.IsSignatureType);
return signatureType.TryResolve(genericMethod.GetGenericArguments());
}

private static Type? TryResolve(this Type signatureType, Type[] genericMethodParameters)
{
Debug.Assert(signatureType.IsSignatureType());
Debug.Assert(signatureType.IsSignatureType);

if (signatureType.IsSZArray())
if (signatureType.IsSZArray)
{
return signatureType.GetElementType()!.TryResolve(genericMethodParameters)?.TryMakeArrayType();
}
else if (signatureType.IsVariableBoundArray())
else if (signatureType.IsVariableBoundArray)
{
return signatureType.GetElementType()!.TryResolve(genericMethodParameters)?.TryMakeArrayType(signatureType.GetArrayRank());
}
Expand All @@ -136,7 +136,7 @@ internal static bool MatchesExactly(this Type pattern, Type actual)
for (int i = 0; i < count; i++)
{
Type genericTypeArgument = genericTypeArguments[i];
if (genericTypeArgument.IsSignatureType())
if (genericTypeArgument.IsSignatureType)
{
newGenericTypeArguments[i] = genericTypeArgument.TryResolve(genericMethodParameters);
if (newGenericTypeArguments[i] == null)
Expand All @@ -149,7 +149,7 @@ internal static bool MatchesExactly(this Type pattern, Type actual)
}
return signatureType.GetGenericTypeDefinition().TryMakeGenericType(newGenericTypeArguments!);
}
else if (signatureType.IsGenericMethodParameter())
else if (signatureType.IsGenericMethodParameter)
{
int position = signatureType.GenericParameterPosition;
if (position >= genericMethodParameters.Length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ private static bool CanCastTo(this Type fromTypeInfo, Type toTypeInfo, CoreTypes
if (rank != toTypeInfo.GetArrayRank())
return false;

bool fromTypeIsSzArray = fromTypeInfo.IsSZArray();
bool toTypeIsSzArray = toTypeInfo.IsSZArray();
bool fromTypeIsSzArray = fromTypeInfo.IsSZArray;
bool toTypeIsSzArray = toTypeInfo.IsSZArray;
if (fromTypeIsSzArray != toTypeIsSzArray)
{
// T[] is assignable to T[*] but not vice-versa.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@

namespace System.Reflection.TypeLoading
{
internal static class NetCoreApiEmulators
{
// On NetCore, call the real thing.

public static bool IsSignatureType(this Type type) => type.IsSignatureType;
public static bool IsSZArray(this Type type) => type.IsSZArray;
public static bool IsVariableBoundArray(this Type type) => type.IsVariableBoundArray;
public static bool IsGenericMethodParameter(this Type type) => type.IsGenericMethodParameter;
public static Type MakeSignatureGenericType(this Type genericTypeDefinition, Type[] typeArguments) => Type.MakeGenericSignatureType(genericTypeDefinition, typeArguments);
}

/// <summary>
/// Another layer of base types. Empty for NetCore.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@

namespace System.Reflection.TypeLoading
{
// For code that have to interact with "Type" rather than "RoType", some handy extension methods that "add" the NetCore reflection apis to NetStandard.
// For code that has to interact with "Type" rather than "RoType", some handy extensions that "add" the NetCore reflection APIs to NetStandard.
internal static class NetCoreApiEmulators
{
// On NetStandard, have to do with slower emulations.
#pragma warning disable IDE0060
public static bool IsSignatureType(this Type type) => false;
public static bool IsSZArray(this Type type) => type.IsArray && type.GetArrayRank() == 1 && type.Name.EndsWith("[]", StringComparison.Ordinal);
public static bool IsVariableBoundArray(this Type type) => type.IsArray && !type.IsSZArray();
public static bool IsGenericMethodParameter(this Type type) => type.IsGenericParameter && type.DeclaringMethod != null;
// On NetStandard, have to do with slower emulations.
extension(Type type)
{
#pragma warning disable CA1822 // Mark members as static
public bool IsSignatureType => false;
#pragma warning restore CA1822 // Mark members as static

public bool IsSZArray => type.IsArray && type.GetArrayRank() == 1 && type.Name.EndsWith("[]", StringComparison.Ordinal);

public bool IsVariableBoundArray => type.IsArray && !type.IsSZArray;

// Signature Types do not exist on NetStandard 2.0 but it's possible we could reach this if a NetCore app uses the NetStandard build of this library.
public static Type MakeSignatureGenericType(this Type genericTypeDefinition, Type[] typeArguments) => throw new NotSupportedException(SR.NotSupported_MakeGenericType_SignatureTypes);
public bool IsGenericMethodParameter => type.IsGenericParameter && type.DeclaringMethod != null;
}
extension(Type)
{
// Signature Types do not exist on NetStandard 2.0 but it's possible we could reach this if a NetCore app uses the NetStandard build of this library.
public static Type MakeGenericSignatureType(Type genericTypeDefinition, params Type[] typeArguments) => throw new NotSupportedException(SR.NotSupported_MakeGenericType_SignatureTypes);
}
#pragma warning restore IDE0060
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public sealed override Type MakeGenericType(params Type[] typeArguments)
Type typeArgument = typeArguments[i];
if (typeArgument == null)
throw new ArgumentNullException();
if (typeArgument.IsSignatureType())
if (typeArgument.IsSignatureType)
{
foundSigType = true;
}
Expand All @@ -117,7 +117,7 @@ public sealed override Type MakeGenericType(params Type[] typeArguments)
}
}
if (foundSigType)
return this.MakeSignatureGenericType(typeArguments);
return Type.MakeGenericSignatureType(this, typeArguments);

// We are intentionally not validating constraints as constraint validation is an execution-time issue that does not block our
// library and should not block a metadata inspection tool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override Type[] GetOptionalCustomModifiers()
public override bool IsGenericTypeDefinition => _unmodifiedType.IsGenericTypeDefinition;
protected override bool HasElementTypeImpl() => _unmodifiedType.Call_HasElementTypeImpl();
protected override bool IsArrayImpl() => _unmodifiedType.Call_IsArrayImpl();
public override bool IsSZArray => _unmodifiedType.IsSZArray();
public override bool IsSZArray => _unmodifiedType.IsSZArray;
public override bool IsVariableBoundArray => _unmodifiedType.IsVariableBoundArray;
protected override bool IsByRefImpl() => _unmodifiedType.Call_IsByRefImpl();
protected override bool IsPointerImpl() => _unmodifiedType.Call_IsPointerImpl();
Expand Down
Loading