Skip to content

Commit ce15692

Browse files
committed
Fix searching for private methods in base classes
1 parent 15eba1c commit ce15692

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

Assets/Editor Toolbox/Editor/Utilities/ReflectionUtility.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,31 @@ internal static MethodInfo GetObjectMethod(string methodName, BindingFlags bindi
4040
}
4141

4242
var targetType = targetObjects[0].GetType();
43-
var methodInfo = targetType.GetMethod(methodName,
44-
bindingFlags, null, CallingConventions.Any, new Type[0], null);
43+
var methodInfo = GetObjectMethod(targetType, methodName, bindingFlags);
44+
if (methodInfo == null && bindingFlags.HasFlag(BindingFlags.NonPublic))
45+
{
46+
//NOTE: if a method is not found and we searching for a private method we should look into parent classes
47+
var baseType = targetType.BaseType;
48+
while (baseType != null)
49+
{
50+
methodInfo = GetObjectMethod(baseType, methodName, bindingFlags);
51+
if (methodInfo != null)
52+
{
53+
break;
54+
}
55+
56+
baseType = baseType.BaseType;
57+
}
58+
}
59+
4560
return methodInfo;
4661
}
4762

63+
internal static MethodInfo GetObjectMethod(Type targetType, string methodName, BindingFlags bindingFlags)
64+
{
65+
return targetType.GetMethod(methodName, bindingFlags, null, CallingConventions.Any, new Type[0], null);
66+
}
67+
4868
/// <summary>
4969
/// Tries to invoke parameterless method located in associated <see cref="Object"/>s.
5070
/// </summary>

0 commit comments

Comments
 (0)