Model: Implement GenericParameterPosition for TypeRefs
This commit is contained in:
@@ -352,7 +352,13 @@ namespace Il2CppInspector.Reflection {
|
||||
|
||||
public GenericParameterAttributes GenericParameterAttributes { get; }
|
||||
|
||||
public int GenericParameterPosition { get; }
|
||||
// Generic parameter position in list of non-concrete type parameters
|
||||
// See: https://docs.microsoft.com/en-us/dotnet/api/system.type.genericparameterposition?view=netframework-4.8
|
||||
private int genericParameterPosition;
|
||||
public int GenericParameterPosition {
|
||||
get => IsGenericParameter ? genericParameterPosition : throw new InvalidOperationException("The current type does not represent a type parameter");
|
||||
private set => genericParameterPosition = value;
|
||||
}
|
||||
|
||||
public List<TypeInfo> GenericTypeParameters { get; }
|
||||
|
||||
@@ -613,7 +619,6 @@ namespace Il2CppInspector.Reflection {
|
||||
foreach (var pArg in genericTypeArguments) {
|
||||
var argType = model.GetTypeFromVirtualAddress((ulong) pArg);
|
||||
// TODO: Detect whether unresolved or concrete (add concrete to GenericTypeArguments instead)
|
||||
// TODO: GenericParameterPosition etc. in types we generate here
|
||||
// TODO: Assembly etc.
|
||||
GenericTypeArguments.Add(argType); // TODO: Fix MemberType here
|
||||
}
|
||||
@@ -682,6 +687,9 @@ namespace Il2CppInspector.Reflection {
|
||||
if (container.is_method == 1)
|
||||
DeclaringMethod = model.MethodsByDefinitionIndex[container.ownerIndex];
|
||||
|
||||
// Set position in argument list
|
||||
GenericParameterPosition = paramType.num;
|
||||
|
||||
IsGenericParameter = true;
|
||||
ContainsGenericParameters = true;
|
||||
IsGenericType = false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||
Copyright 2019-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||
|
||||
All rights reserved.
|
||||
*/
|
||||
@@ -29,31 +29,37 @@ namespace Il2CppInspector
|
||||
var asm = model.GetAssembly("GenericTypes.dll");
|
||||
|
||||
// Act
|
||||
TypeInfo tBase = asm.GetType("Il2CppTests.TestSources.Base`2");
|
||||
TypeInfo tDerived = asm.GetType("Il2CppTests.TestSources.Derived`1");
|
||||
TypeInfo tDerivedBase = tDerived.BaseType;
|
||||
|
||||
// TODO: array of Derived<int>
|
||||
// TypeInfo tDerivedArray
|
||||
|
||||
TypeInfo tT = asm.GetType("Il2CppTests.TestSources.Base`2").GenericTypeParameters[0];
|
||||
TypeInfo tT = tBase.GenericTypeParameters[0];
|
||||
TypeInfo tU = tBase.GenericTypeParameters[1];
|
||||
TypeInfo tF = tDerived.GetField("F").FieldType;
|
||||
TypeInfo tNested = asm.GetType("Il2CppTests.TestSources.Derived`1+Nested");
|
||||
|
||||
DisplayGenericType(tBase, "Generic type definition Base<T, U>");
|
||||
DisplayGenericType(tDerived, "Derived<V>");
|
||||
DisplayGenericType(tDerivedBase, "Base type of Derived<V>");
|
||||
//DisplayGenericType(tDerivedArray, "Array of Derived<int>");
|
||||
DisplayGenericType(tT, "Type parameter T from Base<T>");
|
||||
DisplayGenericType(tT, "Type parameter T from Base<T,U>");
|
||||
DisplayGenericType(tU, "Type parameter U from Base<T,U>");
|
||||
DisplayGenericType(tF, "Field type, G<Derived<V>>");
|
||||
DisplayGenericType(tNested, "Nested type in Derived<V>");
|
||||
|
||||
// Assert
|
||||
var checks = new[] {
|
||||
(tDerived, "Derived`1[V]", true, true, true, false),
|
||||
(tDerivedBase, "Base`2[System.String,V]", true, false, true, false),
|
||||
//(tDerivedArray, "Derived`1[System.Int32][]", false, false, false, false),
|
||||
(tT, "T", false, false, true, true),
|
||||
(tF, "G`1[Derived`1[V]]", true, false, true, false),
|
||||
(tNested, "Derived`1[V]+Nested[V]", true, true, true, false)
|
||||
(tBase, "Base`2[T,U]", true, true, true, false, -1),
|
||||
(tDerived, "Derived`1[V]", true, true, true, false, -1),
|
||||
(tDerivedBase, "Base`2[System.String,V]", true, false, true, false, -1),
|
||||
//(tDerivedArray, "Derived`1[System.Int32][]", false, false, false, false, -1),
|
||||
(tT, "T", false, false, true, true, 0),
|
||||
(tU, "U", false, false, true, true, 1),
|
||||
(tF, "G`1[Derived`1[V]]", true, false, true, false, -1),
|
||||
(tNested, "Derived`1[V]+Nested[V]", true, true, true, false, -1)
|
||||
};
|
||||
|
||||
foreach (var check in checks) {
|
||||
@@ -75,6 +81,9 @@ namespace Il2CppInspector
|
||||
Console.WriteLine("\t IsGenericTypeDefinition: {0}", t.IsGenericTypeDefinition);
|
||||
Console.WriteLine("\tContainsGenericParameters: {0}", t.ContainsGenericParameters);
|
||||
Console.WriteLine("\t IsGenericParameter: {0}", t.IsGenericParameter);
|
||||
|
||||
if (t.IsGenericParameter)
|
||||
Console.WriteLine("\t GenericParameterPosition: {0}", t.GenericParameterPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2017-2019 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||
Copyright 2017-2020 Katy Coe - http://www.hearthcode.org - http://www.djkaty.com
|
||||
|
||||
All rights reserved.
|
||||
*/
|
||||
@@ -45,6 +45,8 @@ namespace Il2CppTests.TestSources
|
||||
Type tF = tDerived.GetField("F").FieldType;
|
||||
Type tNested = typeof(Derived<>.Nested);
|
||||
}
|
||||
|
||||
private void forceTypeReferenceToDerivedIntArray(Derived<int> typeRef) {}
|
||||
}
|
||||
|
||||
// Constraints on type definitions
|
||||
|
||||
Reference in New Issue
Block a user