/// <summary> /// Uses reflection to locate a matching method /// on the target object. /// </summary> /// <param name="objectType"> /// Type of object containing method. /// </param> /// <param name="method"> /// Name of the method. /// </param> /// <param name="parameters"> /// Parameters to pass to method. /// </param> public static MethodInfo GetMethod(Type objectType, string method, params object[] parameters) { MethodInfo methodInfo = null; object[] array = null; object[] arg_11_0 = parameters; if (parameters == null) { object[] array2 = new object[1]; arg_11_0 = array2; } array = arg_11_0; methodInfo = MethodCaller.FindMethod(objectType, method, MethodCaller.GetParameterTypes(array)); if (methodInfo == null) { try { methodInfo = MethodCaller.FindMethod(objectType, method, array.Length); } catch (AmbiguousMatchException) { methodInfo = MethodCaller.FindMethodUsingFuzzyMatching(objectType, method, array); } } if (methodInfo == null) { methodInfo = objectType.GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); } return(methodInfo); }
internal static DynamicMemberHandle GetCachedProperty(Type objectType, string propertyName) { MethodCacheKey key = new MethodCacheKey(objectType.FullName, propertyName, MethodCaller.GetParameterTypes(null)); DynamicMemberHandle dynamicMemberHandle = null; if (MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { return(dynamicMemberHandle); } lock (MethodCaller._memberCache) { if (!MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { PropertyInfo propertyInfo = MethodCaller.FindProperty(objectType, propertyName); if (propertyInfo != null) { dynamicMemberHandle = new DynamicMemberHandle(propertyInfo); } MethodCaller._memberCache.Add(key, dynamicMemberHandle); } } return(dynamicMemberHandle); }
private static DynamicMethodHandle GetCachedMethod(object obj, string method, params object[] parameters) { MethodCacheKey key = new MethodCacheKey(obj.GetType().FullName, method, MethodCaller.GetParameterTypes(parameters)); DynamicMethodHandle dynamicMethodHandle = null; if (MethodCaller._methodCache.TryGetValue(key, out dynamicMethodHandle)) { return(dynamicMethodHandle); } lock (MethodCaller._methodCache) { if (!MethodCaller._methodCache.TryGetValue(key, out dynamicMethodHandle)) { MethodInfo method2 = MethodCaller.GetMethod(obj.GetType(), method, parameters); dynamicMethodHandle = new DynamicMethodHandle(method2, parameters); MethodCaller._methodCache.Add(key, dynamicMethodHandle); } } return(dynamicMethodHandle); }
internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { MethodCacheKey key = new MethodCacheKey(objectType.FullName, fieldName, MethodCaller.GetParameterTypes(null)); DynamicMemberHandle dynamicMemberHandle = null; if (MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { return(dynamicMemberHandle); } lock (MethodCaller._memberCache) { if (!MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { FieldInfo field = objectType.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { dynamicMemberHandle = new DynamicMemberHandle(field); } MethodCaller._memberCache.Add(key, dynamicMemberHandle); } } return(dynamicMemberHandle); }