Change generic params/args to arrays
The C# functions for GetGenericParameters/GetGenericArguments use Type[], not lists, so we should conform to that. Also fix the definition of IsGenericTypeDefinition - because it's possible for a class to be instantiated with all generic parameters.
This commit is contained in:
@@ -146,12 +146,12 @@ namespace Il2CppInspector.Reflection
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get generic arguments from either a type or method instanceIndex from a MethodSpec
|
// Get generic arguments from either a type or method instanceIndex from a MethodSpec
|
||||||
public List<TypeInfo> ResolveGenericArguments(Il2CppGenericInst inst) {
|
public TypeInfo[] ResolveGenericArguments(Il2CppGenericInst inst) {
|
||||||
|
|
||||||
// Get list of pointers to type parameters (both unresolved and concrete)
|
// Get list of pointers to type parameters (both unresolved and concrete)
|
||||||
var genericTypeArguments = Package.BinaryImage.ReadMappedWordArray(inst.type_argv, (int)inst.type_argc);
|
var genericTypeArguments = Package.BinaryImage.ReadMappedWordArray(inst.type_argv, (int)inst.type_argc);
|
||||||
|
|
||||||
return genericTypeArguments.Select(a => GetTypeFromVirtualAddress((ulong) a)).ToList();
|
return genericTypeArguments.Select(a => GetTypeFromVirtualAddress((ulong) a)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a TypeRef by its virtual address
|
// Get a TypeRef by its virtual address
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ namespace Il2CppInspector.Reflection
|
|||||||
// For a generic method definition: the list of generic type parameters
|
// For a generic method definition: the list of generic type parameters
|
||||||
// For an open generic method: a mix of generic type parameters and generic type arguments
|
// For an open generic method: a mix of generic type parameters and generic type arguments
|
||||||
// For a closed generic method: the list of generic type arguments
|
// For a closed generic method: the list of generic type arguments
|
||||||
private readonly List<TypeInfo> genericArguments = new List<TypeInfo>();
|
private readonly TypeInfo[] genericArguments = Array.Empty<TypeInfo>();
|
||||||
|
|
||||||
// See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.getgenericarguments?view=netframework-4.8
|
// See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.getgenericarguments?view=netframework-4.8
|
||||||
public List<TypeInfo> GetGenericArguments() => genericArguments;
|
public TypeInfo[] GetGenericArguments() => genericArguments;
|
||||||
|
|
||||||
// This was added in .NET Core 2.1 and isn't properly documented yet
|
// 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 && genericArguments.All(ga => !ga.ContainsGenericParameters);
|
||||||
@@ -105,7 +105,7 @@ namespace Il2CppInspector.Reflection
|
|||||||
// Store the generic type parameters for later instantiation
|
// Store the generic type parameters for later instantiation
|
||||||
var container = pkg.GenericContainers[Definition.genericContainerIndex];
|
var container = pkg.GenericContainers[Definition.genericContainerIndex];
|
||||||
|
|
||||||
genericArguments = pkg.GenericParameters.Skip((int)container.genericParameterStart).Take(container.type_argc).Select(p => new TypeInfo(this, p)).ToList();
|
genericArguments = pkg.GenericParameters.Skip((int)container.genericParameterStart).Take(container.type_argc).Select(p => new TypeInfo(this, p)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set method attributes
|
// Set method attributes
|
||||||
|
|||||||
@@ -481,14 +481,14 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// For a generic type definition: the list of generic type parameters
|
// For a generic type definition: the list of generic type parameters
|
||||||
// For an open generic type: a mix of generic type parameters and generic type arguments
|
// For an open generic type: a mix of generic type parameters and generic type arguments
|
||||||
// For a closed generic type: the list of generic type arguments
|
// For a closed generic type: the list of generic type arguments
|
||||||
private readonly List<TypeInfo> genericArguments = new List<TypeInfo>();
|
private readonly TypeInfo[] genericArguments = Array.Empty<TypeInfo>();
|
||||||
|
|
||||||
public List<TypeInfo> GenericTypeParameters => IsGenericTypeDefinition ? genericArguments : new List<TypeInfo>();
|
public TypeInfo[] GenericTypeParameters => IsGenericTypeDefinition ? genericArguments : Array.Empty<TypeInfo>();
|
||||||
|
|
||||||
public List<TypeInfo> GenericTypeArguments => !IsGenericTypeDefinition ? genericArguments : new List<TypeInfo>();
|
public TypeInfo[] GenericTypeArguments => !IsGenericTypeDefinition ? genericArguments : Array.Empty<TypeInfo>();
|
||||||
|
|
||||||
// See: https://docs.microsoft.com/en-us/dotnet/api/system.type.getgenericarguments?view=netframework-4.8
|
// See: https://docs.microsoft.com/en-us/dotnet/api/system.type.getgenericarguments?view=netframework-4.8
|
||||||
public List<TypeInfo> GetGenericArguments() => genericArguments;
|
public TypeInfo[] GetGenericArguments() => genericArguments;
|
||||||
|
|
||||||
// True if an array, pointer or reference, otherwise false
|
// True if an array, pointer or reference, otherwise false
|
||||||
// See: https://docs.microsoft.com/en-us/dotnet/api/system.type.haselementtype?view=netframework-4.8
|
// See: https://docs.microsoft.com/en-us/dotnet/api/system.type.haselementtype?view=netframework-4.8
|
||||||
@@ -504,7 +504,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
public bool IsEnum => enumUnderlyingTypeReference != -1;
|
public bool IsEnum => enumUnderlyingTypeReference != -1;
|
||||||
public bool IsGenericParameter { get; }
|
public bool IsGenericParameter { get; }
|
||||||
public bool IsGenericType { get; }
|
public bool IsGenericType { get; }
|
||||||
public bool IsGenericTypeDefinition => genericArguments.Any() && genericArguments.All(a => a.IsGenericTypeParameter);
|
public bool IsGenericTypeDefinition => (Definition != null) && genericArguments.Any();
|
||||||
public bool IsImport => (Attributes & TypeAttributes.Import) == TypeAttributes.Import;
|
public bool IsImport => (Attributes & TypeAttributes.Import) == TypeAttributes.Import;
|
||||||
public bool IsInterface => (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
|
public bool IsInterface => (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
|
||||||
public bool IsNested => (MemberType & MemberTypes.NestedType) == MemberTypes.NestedType;
|
public bool IsNested => (MemberType & MemberTypes.NestedType) == MemberTypes.NestedType;
|
||||||
@@ -577,7 +577,7 @@ namespace Il2CppInspector.Reflection {
|
|||||||
// Store the generic type parameters for later instantiation
|
// Store the generic type parameters for later instantiation
|
||||||
var container = pkg.GenericContainers[Definition.genericContainerIndex];
|
var container = pkg.GenericContainers[Definition.genericContainerIndex];
|
||||||
|
|
||||||
genericArguments = pkg.GenericParameters.Skip((int) container.genericParameterStart).Take(container.type_argc).Select(p => new TypeInfo(this, p)).ToList();
|
genericArguments = pkg.GenericParameters.Skip((int) container.genericParameterStart).Take(container.type_argc).Select(p => new TypeInfo(this, p)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to global type definition list
|
// Add to global type definition list
|
||||||
|
|||||||
Reference in New Issue
Block a user