public static object Invoke(Controller controller, IList<MethodSchema> methods, object[] args) { Type[] argsType = new Type[args.Length]; for (int i = 0; i < args.Length; i++) { if (args[i] == null) throw new MissingMethodException(); argsType[i] = args[i].GetType(); } MethodSchema currentMethod = null; foreach (MethodSchema m in methods) { if (m.Parameters.Length != args.Length) continue; bool found = true; for (int i = 0; i < argsType.Length; i++) { if (m.Parameters[i].ParameterType != argsType[i]) { found = false; break; } } if (found) { currentMethod = m; break; } } if (currentMethod != null) { return currentMethod.InvokeHandler.Invoke(controller, args); } else { throw new MissingMethodException(); } }
public bool Run(Controller controller, string methodName) { try { MethodSchema data; if (_publicMethods.TryGetValue(methodName, out data)) { foreach (MethodSchema beforeData in _beforeMethods) { beforeData.InvokeHandler.Invoke(controller, WebAppHelper.CreateParameters(beforeData.Parameters, controller.ViewData)); } data.InvokeHandler.Invoke(controller, WebAppHelper.CreateParameters(data.Parameters, controller.ViewData)); foreach (MethodSchema afterData in _afterMethods) { afterData.InvokeHandler.Invoke(controller, WebAppHelper.CreateParameters(afterData.Parameters, controller.ViewData)); } } else { throw new InvokeException(methodName, controller.GetType()); } return true; } catch (TargetInvocationException ex) { #if MEDIUMLEVEL throw ex.InnerException; #else FieldInfo remoteStackTrace = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic); remoteStackTrace.SetValue(ex.InnerException, ex.InnerException.StackTrace + "\r\n"); throw ex.InnerException; #endif } }