From 4f54c7a85e282fc2830553105ef2f79ed23cd11f Mon Sep 17 00:00:00 2001 From: Katy Coe Date: Sat, 9 Nov 2019 22:15:26 +0100 Subject: [PATCH] Model: Add TypeInfo.GetMethods(string) and TypeInfo.GetAllMethods() --- Il2CppInspector/Reflection/TypeInfo.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index 38bcc80..b0ce9ac 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -87,6 +87,19 @@ namespace Il2CppInspector.Reflection { // Get a method by its name public MethodInfo GetMethod(string name) => DeclaredMethods.FirstOrDefault(m => m.Name == name); + // Get all methods with same name (overloads) + public MethodInfo[] GetMethods(string name) => DeclaredMethods.Where(m => m.Name == Name).ToArray(); + + // Get methods including inherited methods + public MethodInfo[] GetAllMethods() { + var methods = new List>(); + + for (var type = this; type != null; type = type.BaseType) + methods.Add(type.DeclaredMethods); + + return methods.SelectMany(m => m).ToArray(); + } + // Get a property by its name public PropertyInfo GetProperty(string name) => DeclaredProperties.FirstOrDefault(p => p.Name == name);