Model: Substitute concrete parameter types into generic methods from MethodSpecs

This commit is contained in:
Katy Coe
2020-02-02 04:45:43 +01:00
parent d2cb63dc95
commit 759a77031e
3 changed files with 20 additions and 3 deletions

View File

@@ -152,7 +152,14 @@ namespace Il2CppInspector.Reflection
IsGenericMethod = true;
genericArguments = model.ResolveGenericArguments(spec.methodIndexIndex);
// TODO: Substitute generic type arguments for concrete type arguments
// Substitute matching generic type parameters with concrete type arguments
foreach (var p in methodDef.DeclaredParameters) {
if (!p.ParameterType.IsGenericMethodParameter)
DeclaredParameters.Add(p);
else
DeclaredParameters.Add(new ParameterInfo(model, p, genericArguments[p.ParameterType.GenericParameterPosition]));
}
// TODO: Populate VirtualAddress via Il2CppGenericMethodFunctionsDefinitions
}
@@ -219,6 +226,7 @@ namespace Il2CppInspector.Reflection
public string GetTypeParametersString(Scope usingScope) => !GetGenericArguments().Any()? "" :
"<" + string.Join(", ", GetGenericArguments().Select(p => p.GetScopedCSharpName(usingScope))) + ">";
// TODO: The scope output for some System types does not match the real .NET output here
public string GetFullTypeParametersString() => !GetGenericArguments().Any()? "" :
"[" + string.Join(",", GetGenericArguments().Select(p => p.FullName ?? p.Name)) + "]";

View File

@@ -97,7 +97,17 @@ namespace Il2CppInspector.Reflection
// Create a concrete type parameter from a generic type parameter
public ParameterInfo(Il2CppModel model, ParameterInfo generic, TypeInfo concrete) {
// TODO: Implement generic parameter substitution
DeclaringMethod = generic.DeclaringMethod;
Name = generic.Name;
Position = generic.Position;
Attributes = generic.Attributes;
// TODO: Duplicate instances of 'concrete' may cause this search to fail. Replace with a straight lookup after eliminating GetTypeFromVirtualAddress
paramTypeReference = Array.IndexOf(model.TypesByReferenceIndex, concrete);
DefaultValue = generic.DefaultValue;
DefaultValueMetadataAddress = generic.DefaultValueMetadataAddress;
}
// ref will be handled as part of the type name

View File

@@ -6,7 +6,6 @@
using System;
using System.Collections.Generic;
using Il2CppInspector;
namespace Il2CppTests.TestSources
{