public override IMessage Invoke(IMessage msg) { var methodCall = (IMethodCallMessage)msg; var method = (MethodInfo)methodCall.MethodBase; try { object[] inArgs = methodCall.InArgs; object result; FluentProxyActions <T> fluentProxyActions = _configuration.ActionsFor(method.Name); if (fluentProxyActions != null) { fluentProxyActions.BeforeActions?.Invoke(_instance, method, inArgs); result = (fluentProxyActions.BeforeActions != null) ? fluentProxyActions.InsteadOfActions(_instance, method, inArgs) : method.Invoke(_instance, inArgs); fluentProxyActions.AfterActions?.Invoke(_instance, method, inArgs, result); } else { result = method.Invoke(_instance, inArgs); } return(new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall)); } catch (Exception e) { Console.WriteLine("Exception: " + e); if (e is TargetInvocationException && e.InnerException != null) { return(new ReturnMessage(e.InnerException, (IMethodCallMessage)msg)); } return(new ReturnMessage(e, (IMethodCallMessage)msg)); } }
/// <summary> /// Define o método a ser configurado /// </summary> /// <param name="methodName">Nome do método</param> /// <returns>Esta instância</returns> public FluentProxy <T> For(string methodName) { if (_methods.Any(m => m.Name == methodName)) { var fluentProxyActions = new FluentProxyActions <T>(); _actions.Add(methodName, fluentProxyActions); _currentMethod = methodName; } return(this); }
/// <summary> /// Remove quaisquer configurações para o método atual /// </summary> /// <returns>Esta instância</returns> IFluentProxyExecuters <T> IFluentProxyExecuters <T> .Clear() { CheckIfHasCurrentMethod(); _actions[_currentMethod] = new FluentProxyActions <T>(); return(this); }