Fix ContainsGenericParameters and IsGenericMethodDefinition

IsGenericMethodDefinition needs the same treatment as
IsGenericTypeDefinition, i.e. it should depend on whether the class is a
definition as opposed to merely checking if the type args are generic
parameters (which could happen in a partially specialized method).

Also, array/ref/pointer types of generic types are considered to have
generic parameters, so correct ContainsGenericParameters accordingly.
This commit is contained in:
Robert Xiao
2020-04-11 21:18:17 -07:00
committed by Katy
parent ec6018d012
commit 202a802274
2 changed files with 4 additions and 4 deletions

View File

@@ -59,12 +59,12 @@ namespace Il2CppInspector.Reflection
public TypeInfo[] GetGenericArguments() => genericArguments; public TypeInfo[] GetGenericArguments() => genericArguments;
// This was added in .NET Core 2.1 and isn't properly documented yet // This was added in .NET Core 2.1 and isn't properly documented yet
public bool IsConstructedGenericMethod => IsGenericMethod && genericArguments.All(ga => !ga.ContainsGenericParameters); public bool IsConstructedGenericMethod => IsGenericMethod && !IsGenericMethodDefinition;
// See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.isgenericmethod?view=netframework-4.8 // See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.isgenericmethod?view=netframework-4.8
public bool IsGenericMethod { get; } public bool IsGenericMethod { get; }
public bool IsGenericMethodDefinition => genericArguments.Any() && genericArguments.All(a => a.IsGenericMethodParameter); public bool IsGenericMethodDefinition => (Definition != null) && genericArguments.Any();
// TODO: GetMethodBody() // TODO: GetMethodBody()
public string CSharpName => public string CSharpName =>

View File

@@ -99,7 +99,7 @@ namespace Il2CppInspector.Reflection {
} }
// True if the type contains unresolved generic type parameters // True if the type contains unresolved generic type parameters
public bool ContainsGenericParameters => IsGenericParameter || genericArguments.Any(ga => ga.ContainsGenericParameters); public bool ContainsGenericParameters => (HasElementType && ElementType.ContainsGenericParameters) || IsGenericParameter || genericArguments.Any(ga => ga.ContainsGenericParameters);
// Custom attributes for this member // Custom attributes for this member
public override IEnumerable<CustomAttributeData> CustomAttributes => CustomAttributeData.GetCustomAttributes(this); public override IEnumerable<CustomAttributeData> CustomAttributes => CustomAttributeData.GetCustomAttributes(this);