From 7b1d46644dbdc829193b3ff86354314f72584af3 Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sun, 2 Feb 2020 05:17:47 +0100 Subject: [PATCH] Model: Generate ConstructorInfo for generic class constructors from MethodSpecs --- Il2CppInspector/Reflection/ConstructorInfo.cs | 2 ++ Il2CppInspector/Reflection/Il2CppModel.cs | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Il2CppInspector/Reflection/ConstructorInfo.cs b/Il2CppInspector/Reflection/ConstructorInfo.cs index a3ca9bd..da2a760 100644 --- a/Il2CppInspector/Reflection/ConstructorInfo.cs +++ b/Il2CppInspector/Reflection/ConstructorInfo.cs @@ -20,6 +20,8 @@ namespace Il2CppInspector.Reflection public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) { } + public ConstructorInfo(Il2CppModel model, Il2CppMethodSpec spec, TypeInfo declaringType) : base(model, spec, declaringType) { } + public override string ToString() => DeclaringType.Name + GetFullTypeParametersString() + "(" + string.Join(", ", DeclaredParameters.Select(x => x.ParameterType.Name)) + ")"; diff --git a/Il2CppInspector/Reflection/Il2CppModel.cs b/Il2CppInspector/Reflection/Il2CppModel.cs index bde67e7..e6aabb2 100644 --- a/Il2CppInspector/Reflection/Il2CppModel.cs +++ b/Il2CppInspector/Reflection/Il2CppModel.cs @@ -27,7 +27,7 @@ namespace Il2CppInspector.Reflection public Dictionary TypesByMethodSpecClassIndex { get; } = new Dictionary(); // List of all methods from MethodSpecs (closed generic methods that can be called; does not need to be in a generic class) - public Dictionary> GenericMethods { get; } = new Dictionary>(); + public Dictionary> GenericMethods { get; } = new Dictionary>(); // List of all type definitions by fully qualified name (TypeDefs only) public Dictionary TypesByFullName { get; } = new Dictionary(); @@ -90,9 +90,14 @@ namespace Il2CppInspector.Reflection // First generic method declaration in this class? if (!GenericMethods.ContainsKey(declaringType)) - GenericMethods.Add(declaringType, new List()); + GenericMethods.Add(declaringType, new List()); - GenericMethods[declaringType].Add(new MethodInfo(this, spec, declaringType)); + // Method or constructor + var concreteMethod = new MethodInfo(this, spec, declaringType); + if (concreteMethod.Name == ConstructorInfo.ConstructorName || concreteMethod.Name == ConstructorInfo.TypeConstructorName) + GenericMethods[declaringType].Add(new ConstructorInfo(this, spec, declaringType)); + else + GenericMethods[declaringType].Add(concreteMethod); } } }