@@ -192,6 +192,51 @@ public static PropertyInfo GetPropertyInfo(Type type, string propertyName)
192
192
return s_cachedPropInfos [ type ] [ propertyName ] ;
193
193
}
194
194
195
+ internal static Dictionary < Type , Dictionary < string , MethodInfo > > s_cachedMethodInfos = new Dictionary < Type , Dictionary < string , MethodInfo > > ( ) ;
196
+
197
+ public static MethodInfo GetMethodInfo ( Type type , string methodName , Type [ ] argumentTypes )
198
+ {
199
+ if ( ! s_cachedMethodInfos . ContainsKey ( type ) )
200
+ s_cachedMethodInfos . Add ( type , new Dictionary < string , MethodInfo > ( ) ) ;
201
+
202
+ var sig = methodName ;
203
+
204
+ if ( argumentTypes != null )
205
+ {
206
+ sig += "(" ;
207
+ for ( int i = 0 ; i < argumentTypes . Length ; i ++ )
208
+ {
209
+ if ( i > 0 )
210
+ sig += "," ;
211
+ sig += argumentTypes [ i ] . FullName ;
212
+ }
213
+ sig += ")" ;
214
+ }
215
+
216
+ try
217
+ {
218
+ if ( ! s_cachedMethodInfos [ type ] . ContainsKey ( sig ) )
219
+ {
220
+ if ( argumentTypes != null )
221
+ s_cachedMethodInfos [ type ] . Add ( sig , type . GetMethod ( methodName , AllFlags , null , argumentTypes , null ) ) ;
222
+ else
223
+ s_cachedMethodInfos [ type ] . Add ( sig , type . GetMethod ( methodName , AllFlags ) ) ;
224
+ }
225
+
226
+ return s_cachedMethodInfos [ type ] [ sig ] ;
227
+ }
228
+ catch ( AmbiguousMatchException )
229
+ {
230
+ ExplorerCore . LogWarning ( $ "AmbiguousMatchException trying to get method '{ sig } '") ;
231
+ return null ;
232
+ }
233
+ catch ( Exception e )
234
+ {
235
+ ExplorerCore . LogWarning ( $ "{ e . GetType ( ) } trying to get method '{ sig } ': { e . Message } \r \n { e . StackTrace } ") ;
236
+ return null ;
237
+ }
238
+ }
239
+
195
240
/// <summary>
196
241
/// Helper to display a simple "{ExceptionType}: {Message}" of the exception, and optionally use the inner-most exception.
197
242
/// </summary>
0 commit comments