From 202a802274f1d96f78ce14b789ea9f31a35c4b6d Mon Sep 17 00:00:00 2001 From: Robert Xiao Date: Sat, 11 Apr 2020 21:18:17 -0700 Subject: [PATCH] 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. --- Il2CppInspector.Common/Reflection/MethodBase.cs | 6 +++--- Il2CppInspector.Common/Reflection/TypeInfo.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Il2CppInspector.Common/Reflection/MethodBase.cs b/Il2CppInspector.Common/Reflection/MethodBase.cs index c61948e..a7e4c4b 100644 --- a/Il2CppInspector.Common/Reflection/MethodBase.cs +++ b/Il2CppInspector.Common/Reflection/MethodBase.cs @@ -59,12 +59,12 @@ namespace Il2CppInspector.Reflection public TypeInfo[] GetGenericArguments() => genericArguments; // 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 public bool IsGenericMethod { get; } - public bool IsGenericMethodDefinition => genericArguments.Any() && genericArguments.All(a => a.IsGenericMethodParameter); - + public bool IsGenericMethodDefinition => (Definition != null) && genericArguments.Any(); + // TODO: GetMethodBody() public string CSharpName => diff --git a/Il2CppInspector.Common/Reflection/TypeInfo.cs b/Il2CppInspector.Common/Reflection/TypeInfo.cs index 561ea2c..303779b 100644 --- a/Il2CppInspector.Common/Reflection/TypeInfo.cs +++ b/Il2CppInspector.Common/Reflection/TypeInfo.cs @@ -99,7 +99,7 @@ namespace Il2CppInspector.Reflection { } // 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 public override IEnumerable CustomAttributes => CustomAttributeData.GetCustomAttributes(this);