From ec6018d0127e7e6b8a12b3d1f2de19bfee7b78a3 Mon Sep 17 00:00:00 2001 From: Robert Xiao Date: Sat, 11 Apr 2020 18:11:18 -0700 Subject: [PATCH] Add non-generic methods to TestGenerics In order to select the correct generic type, model.GetGenericMethod is changed to use Name (which includes generic parameters) instead of BaseName. The tests for GenericMethodDefinitionInGenericClass* are also changed to reflect the fact that the chosen methods are fully concrete. TestGenerics now passes in its entirety. --- .../Reflection/Il2CppModel.cs | 2 +- Il2CppTests/TestGenerics.cs | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Il2CppInspector.Common/Reflection/Il2CppModel.cs b/Il2CppInspector.Common/Reflection/Il2CppModel.cs index c10034f..0227558 100644 --- a/Il2CppInspector.Common/Reflection/Il2CppModel.cs +++ b/Il2CppInspector.Common/Reflection/Il2CppModel.cs @@ -59,7 +59,7 @@ namespace Il2CppInspector.Reflection // Get a concrete instantiation of a generic method from its fully qualified name and type arguments public MethodBase GetGenericMethod(string fullName, params TypeInfo[] typeArguments) => - GenericMethods.Values.First(m => fullName == m.DeclaringType.Namespace + "." + m.DeclaringType.BaseName + "." + m.Name + GenericMethods.Values.First(m => fullName == m.DeclaringType.Namespace + "." + m.DeclaringType.Name + "." + m.Name && m.GetGenericArguments().SequenceEqual(typeArguments)); // Create type model diff --git a/Il2CppTests/TestGenerics.cs b/Il2CppTests/TestGenerics.cs index d3dd3e8..59fe56c 100644 --- a/Il2CppTests/TestGenerics.cs +++ b/Il2CppTests/TestGenerics.cs @@ -51,10 +51,14 @@ namespace Il2CppInspector MethodBase mGMDINGC_closed = model.GetGenericMethod( "Il2CppTests.TestSources.NonGeneric.GenericMethodDefinitionInNonGenericClass", model.GetType("System.Single")); + MethodBase mNGMIGC_closed = model.GetGenericMethod( + "Il2CppTests.TestSources.GenericClassWithMethods`1[System.Int32].NonGenericMethodInGenericClass"); + MethodBase mNGMIGC2_closed = model.GetGenericMethod( + "Il2CppTests.TestSources.GenericClassWithMethods`1[System.Int32].NonGenericMethodInGenericClass2"); MethodBase mGMDIGC_closed = model.GetGenericMethod( - "Il2CppTests.TestSources.GenericClassWithMethods`1.GenericMethodDefinitionInGenericClass", model.GetType("System.Int32")); + "Il2CppTests.TestSources.GenericClassWithMethods`1[System.Int32].GenericMethodDefinitionInGenericClass", model.GetType("System.Int32")); MethodBase mGMDIGC2_closed = model.GetGenericMethod( - "Il2CppTests.TestSources.GenericClassWithMethods`1.GenericMethodDefinitionInGenericClass2", model.GetType("System.String")); + "Il2CppTests.TestSources.GenericClassWithMethods`1[System.Int32].GenericMethodDefinitionInGenericClass2", model.GetType("System.String")); DisplayGenericType(tBase, "Generic type definition Base"); DisplayGenericType(tDerived, "Derived"); @@ -85,13 +89,10 @@ namespace Il2CppInspector (mGMDIGC2, "Void GenericMethodDefinitionInGenericClass2[U](T, U)", true, true, true, false), (mGMDINGC_closed, "Void GenericMethodDefinitionInNonGenericClass[Single](Single)", true, false, false, true), - // TODO: We can't test non-generic methods in a generic class until we've implemented parameter substitution in TypeInfo constructor - /* (mNGMIGC_closed, "Void NonGenericMethodInGenericClass(Int32)", false, false, false, false), - (mNGMIGC2_closed, "Void NonGenericMethodInGenericClass()", false, false, false, false), - */ - (mGMDIGC_closed, "Void GenericMethodDefinitionInGenericClass[Int32](Int32)", true, true, false, true), - (mGMDIGC2_closed, "Void GenericMethodDefinitionInGenericClass2[String](T, String)", true, true, false, true) // It's actually System.String in .NET + (mNGMIGC2_closed, "Void NonGenericMethodInGenericClass2()", false, false, false, false), + (mGMDIGC_closed, "Void GenericMethodDefinitionInGenericClass[Int32](Int32)", true, false, false, true), + (mGMDIGC2_closed, "Void GenericMethodDefinitionInGenericClass2[String](Int32, String)", true, false, false, true), }; foreach (var check in typeChecks) {