diff --git a/Il2CppInspector.Common/Reflection/Il2CppModel.cs b/Il2CppInspector.Common/Reflection/Il2CppModel.cs index e83764f..2bfb9ae 100644 --- a/Il2CppInspector.Common/Reflection/Il2CppModel.cs +++ b/Il2CppInspector.Common/Reflection/Il2CppModel.cs @@ -146,12 +146,12 @@ namespace Il2CppInspector.Reflection } // Get generic arguments from either a type or method instanceIndex from a MethodSpec - public List ResolveGenericArguments(Il2CppGenericInst inst) { + public TypeInfo[] ResolveGenericArguments(Il2CppGenericInst inst) { // Get list of pointers to type parameters (both unresolved and concrete) 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 diff --git a/Il2CppInspector.Common/Reflection/MethodBase.cs b/Il2CppInspector.Common/Reflection/MethodBase.cs index 23b1e36..10b245b 100644 --- a/Il2CppInspector.Common/Reflection/MethodBase.cs +++ b/Il2CppInspector.Common/Reflection/MethodBase.cs @@ -53,10 +53,10 @@ namespace Il2CppInspector.Reflection // 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 a closed generic method: the list of generic type arguments - private readonly List genericArguments = new List(); + private readonly TypeInfo[] genericArguments = Array.Empty(); // See: https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.getgenericarguments?view=netframework-4.8 - public List GetGenericArguments() => genericArguments; + public TypeInfo[] GetGenericArguments() => genericArguments; // This was added in .NET Core 2.1 and isn't properly documented yet public bool IsConstructedGenericMethod => IsGenericMethod && genericArguments.All(ga => !ga.ContainsGenericParameters); @@ -105,7 +105,7 @@ namespace Il2CppInspector.Reflection // Store the generic type parameters for later instantiation 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 diff --git a/Il2CppInspector.Common/Reflection/TypeInfo.cs b/Il2CppInspector.Common/Reflection/TypeInfo.cs index 82f368e..ab2c198 100644 --- a/Il2CppInspector.Common/Reflection/TypeInfo.cs +++ b/Il2CppInspector.Common/Reflection/TypeInfo.cs @@ -481,14 +481,14 @@ namespace Il2CppInspector.Reflection { // 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 a closed generic type: the list of generic type arguments - private readonly List genericArguments = new List(); + private readonly TypeInfo[] genericArguments = Array.Empty(); - public List GenericTypeParameters => IsGenericTypeDefinition ? genericArguments : new List(); + public TypeInfo[] GenericTypeParameters => IsGenericTypeDefinition ? genericArguments : Array.Empty(); - public List GenericTypeArguments => !IsGenericTypeDefinition ? genericArguments : new List(); + public TypeInfo[] GenericTypeArguments => !IsGenericTypeDefinition ? genericArguments : Array.Empty(); // See: https://docs.microsoft.com/en-us/dotnet/api/system.type.getgenericarguments?view=netframework-4.8 - public List GetGenericArguments() => genericArguments; + public TypeInfo[] GetGenericArguments() => genericArguments; // 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 @@ -504,7 +504,7 @@ namespace Il2CppInspector.Reflection { public bool IsEnum => enumUnderlyingTypeReference != -1; public bool IsGenericParameter { 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 IsInterface => (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface; public bool IsNested => (MemberType & MemberTypes.NestedType) == MemberTypes.NestedType; @@ -577,7 +577,7 @@ namespace Il2CppInspector.Reflection { // Store the generic type parameters for later instantiation 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