@@ -13,6 +13,33 @@ internal static class ReflectionUtility
1313 public const BindingFlags allBindings = BindingFlags . Instance |
1414 BindingFlags . Static | BindingFlags . NonPublic | BindingFlags . Public ;
1515
16+ internal static FieldInfo GetField ( Type targetType , string fieldName )
17+ {
18+ return GetField ( targetType , fieldName , allBindings ) ;
19+ }
20+
21+ internal static FieldInfo GetField ( Type targetType , string fieldName , BindingFlags bindingFlags )
22+ {
23+ var field = targetType . GetField ( fieldName , bindingFlags ) ;
24+ if ( field == null && bindingFlags . HasFlag ( BindingFlags . NonPublic ) )
25+ {
26+ //NOTE: if a method is not found and we searching for a private method we should look into parent classes
27+ Type baseType = targetType . BaseType ;
28+ while ( baseType != null )
29+ {
30+ field = baseType . GetField ( fieldName , bindingFlags ) ;
31+ if ( field != null )
32+ {
33+ break ;
34+ }
35+
36+ baseType = baseType . BaseType ;
37+ }
38+ }
39+
40+ return field ;
41+ }
42+
1643 /// <summary>
1744 /// Returns <see cref="MethodInfo"/> of the searched method within the Editor <see cref="Assembly"/>.
1845 /// </summary>
@@ -21,32 +48,42 @@ internal static MethodInfo GetEditorMethod(string classType, string methodName,
2148 return editorAssembly . GetType ( classType ) . GetMethod ( methodName , falgs ) ;
2249 }
2350
24- internal static MethodInfo GetObjectMethod ( string methodName , SerializedObject serializedObject )
51+ internal static MethodInfo GetMethod ( string methodName , SerializedObject serializedObject )
2552 {
26- return GetObjectMethod ( methodName , serializedObject . targetObjects ) ;
53+ return GetMethod ( methodName , serializedObject . targetObjects ) ;
2754 }
2855
29- internal static MethodInfo GetObjectMethod ( string methodName , params object [ ] targetObjects )
56+ internal static MethodInfo GetMethod ( string methodName , params object [ ] targetObjects )
3057 {
31- return GetObjectMethod ( methodName , allBindings , targetObjects ) ;
58+ return GetMethod ( methodName , allBindings , targetObjects ) ;
3259 }
3360
34- internal static MethodInfo GetObjectMethod ( string methodName , BindingFlags bindingFlags , params object [ ] targetObjects )
61+ internal static MethodInfo GetMethod ( string methodName , BindingFlags bindingFlags , params object [ ] targetObjects )
3562 {
3663 if ( targetObjects == null || targetObjects . Length == 0 )
3764 {
3865 return null ;
3966 }
4067
4168 var targetType = targetObjects [ 0 ] . GetType ( ) ;
42- var methodInfo = GetObjectMethod ( targetType , methodName , bindingFlags ) ;
69+ return GetMethod ( targetType , methodName , bindingFlags ) ;
70+ }
71+
72+ internal static MethodInfo GetMethod ( Type targetType , string methodName )
73+ {
74+ return GetMethod ( targetType , methodName , allBindings ) ;
75+ }
76+
77+ internal static MethodInfo GetMethod ( Type targetType , string methodName , BindingFlags bindingFlags )
78+ {
79+ var methodInfo = targetType . GetMethod ( methodName , bindingFlags , null , CallingConventions . Any , new Type [ 0 ] , null ) ;
4380 if ( methodInfo == null && bindingFlags . HasFlag ( BindingFlags . NonPublic ) )
4481 {
4582 //NOTE: if a method is not found and we searching for a private method we should look into parent classes
4683 var baseType = targetType . BaseType ;
4784 while ( baseType != null )
4885 {
49- methodInfo = GetObjectMethod ( baseType , methodName , bindingFlags ) ;
86+ methodInfo = baseType . GetMethod ( methodName , bindingFlags , null , CallingConventions . Any , new Type [ 0 ] , null ) ;
5087 if ( methodInfo != null )
5188 {
5289 break ;
@@ -59,9 +96,31 @@ internal static MethodInfo GetObjectMethod(string methodName, BindingFlags bindi
5996 return methodInfo ;
6097 }
6198
62- internal static MethodInfo GetObjectMethod ( Type targetType , string methodName , BindingFlags bindingFlags )
99+ internal static PropertyInfo GetProperty ( Type targetType , string propertyName )
100+ {
101+ return GetProperty ( targetType , propertyName , allBindings ) ;
102+ }
103+
104+ internal static PropertyInfo GetProperty ( Type targetType , string propertyName , BindingFlags bindingFlags )
63105 {
64- return targetType . GetMethod ( methodName , bindingFlags , null , CallingConventions . Any , new Type [ 0 ] , null ) ;
106+ var property = targetType . GetProperty ( propertyName , bindingFlags ) ;
107+ if ( property == null && bindingFlags . HasFlag ( BindingFlags . NonPublic ) )
108+ {
109+ //NOTE: if a method is not found and we searching for a private method we should look into parent classes
110+ Type baseType = targetType . BaseType ;
111+ while ( baseType != null )
112+ {
113+ property = baseType . GetProperty ( propertyName , bindingFlags ) ;
114+ if ( property != null )
115+ {
116+ break ;
117+ }
118+
119+ baseType = baseType . BaseType ;
120+ }
121+ }
122+
123+ return property ;
65124 }
66125
67126 /// <summary>
@@ -70,7 +129,7 @@ internal static MethodInfo GetObjectMethod(Type targetType, string methodName, B
70129 internal static bool TryInvokeMethod ( string methodName , SerializedObject serializedObject )
71130 {
72131 var targetObjects = serializedObject . targetObjects ;
73- var method = GetObjectMethod ( methodName , targetObjects ) ;
132+ var method = GetMethod ( methodName , targetObjects ) ;
74133 if ( method == null )
75134 {
76135 return false ;
0 commit comments