Model: Add TypeInfo.GetMethods(string) and TypeInfo.GetAllMethods()

This commit is contained in:
Katy Coe
2019-11-09 22:15:26 +01:00
parent 88a18997ee
commit 4f54c7a85e

View File

@@ -87,6 +87,19 @@ namespace Il2CppInspector.Reflection {
// Get a method by its name // Get a method by its name
public MethodInfo GetMethod(string name) => DeclaredMethods.FirstOrDefault(m => m.Name == 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<IEnumerable<MethodInfo>>();
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 // Get a property by its name
public PropertyInfo GetProperty(string name) => DeclaredProperties.FirstOrDefault(p => p.Name == name); public PropertyInfo GetProperty(string name) => DeclaredProperties.FirstOrDefault(p => p.Name == name);