Implement constructors & methods on constructed generics.
We adopt roughly the same approach as the C# Reflection API: a GenericMethodDefinition is a method which has no method parameters substituted, but lives in a open or closed type with some or all type parameters substituted. To ensure the uniqueness of the MethodInfo, we cache by the method type arguments, and also cache generated DeclaredConstructors/DeclaredMethods in the TypeInfo. This also enables MakeGenericMethod, albeit in a slightly different form than the Reflection API: MakeGenericMethod lives in MethodBase, so it's callable from a constructor (even though in C# constructors cannot be generic). This slight violation of the spec reduces code duplication, so it's probably worth it. Finally, VirtualAddress gets set when populating GenericMethods, and so it'll work whether or not the methods get cached/generated ahead of time.
This commit is contained in:
@@ -98,11 +98,19 @@ namespace Il2CppInspector.Reflection
|
||||
declaringType = declaringType.MakeGenericType(genericArguments);
|
||||
}
|
||||
|
||||
// Concrete instance of a generic method
|
||||
if (methodDefinition is MethodInfo)
|
||||
GenericMethods[spec] = new MethodInfo(this, spec, declaringType);
|
||||
MethodBase method;
|
||||
if (methodDefinition is ConstructorInfo)
|
||||
method = declaringType.GetConstructorByDefinition((ConstructorInfo)methodDefinition);
|
||||
else
|
||||
GenericMethods[spec] = new ConstructorInfo(this, spec, declaringType);
|
||||
method = declaringType.GetMethodByDefinition((MethodInfo)methodDefinition);
|
||||
|
||||
if (spec.methodIndexIndex != -1) {
|
||||
var genericInstance = Package.GenericInstances[spec.methodIndexIndex];
|
||||
var genericArguments = ResolveGenericArguments(genericInstance);
|
||||
method = method.MakeGenericMethod(genericArguments);
|
||||
}
|
||||
method.VirtualAddress = Package.GetGenericMethodPointer(spec);
|
||||
GenericMethods[spec] = method;
|
||||
}
|
||||
|
||||
// Find all custom attribute generators (populate AttributesByIndices) (use ToList() to force evaluation)
|
||||
|
||||
Reference in New Issue
Block a user