Introduce a cache for generic type instantiations.

Also add MakeGenericType, which creates type instances from a generic
type definition and arguments. We will use this later to build properly
fleshed out concrete generic types.
This commit is contained in:
Robert Xiao
2020-04-11 00:25:49 -07:00
committed by Katy
parent 648840c714
commit ab5fc836a1
2 changed files with 39 additions and 5 deletions

View File

@@ -94,7 +94,8 @@ namespace Il2CppInspector.Reflection
if (!TypesByMethodSpecClassIndex.ContainsKey(spec.classIndexIndex)) {
var genericTypeDefinition = MethodsByDefinitionIndex[spec.methodDefinitionIndex].DeclaringType;
var genericInstance = Package.GenericInstances[spec.classIndexIndex];
TypesByMethodSpecClassIndex.Add(spec.classIndexIndex, new TypeInfo(genericTypeDefinition, genericInstance));
var genericArguments = ResolveGenericArguments(genericInstance);
TypesByMethodSpecClassIndex.Add(spec.classIndexIndex, genericTypeDefinition.MakeGenericType(genericArguments));
}
declaringType = TypesByMethodSpecClassIndex[spec.classIndexIndex];