public override IMessage Invoke(IMessage msg) { Guard.ArgumentNotNull(msg, "msg"); IMethodCallMessage callMessage = (IMethodCallMessage)msg; if (callMessage.MethodBase.DeclaringType == typeof(IInterceptingProxy)) { return(HandleInterceptingProxyMethod(callMessage)); } HandlerPipeline pipeline = GetPipeline(TranslateInterfaceMethod(callMessage.MethodBase)); TransparentProxyMethodInvocation invocation = new TransparentProxyMethodInvocation(callMessage, target); IMethodReturn result = pipeline.Invoke( invocation, delegate(IMethodInvocation input, GetNextHandlerDelegate getNext) { try { object returnValue = callMessage.MethodBase.Invoke(target, invocation.Arguments); return(input.CreateMethodReturn(returnValue, invocation.Arguments)); } catch (TargetInvocationException ex) { // The outer exception will always be a reflection exception; we want the inner, which is // the underlying exception. return(input.CreateExceptionMethodReturn(ex.InnerException)); } }); return(((TransparentProxyMethodReturn)result).ToMethodReturnMessage()); }
public override IMessage Invoke(IMessage msg) { Guard.ArgumentNotNull(msg, "msg"); IMethodCallMessage callMessage = (IMethodCallMessage)msg; if (callMessage.MethodBase.DeclaringType == typeof(IInterceptingProxy)) { return(this.HandleInterceptingProxyMethod(callMessage)); } TransparentProxyMethodInvocation invocation = new TransparentProxyMethodInvocation(callMessage, this.target); IMethodReturn result = this.interceptorsPipeline.Invoke( invocation, delegate(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { if (callMessage.MethodBase.DeclaringType.IsAssignableFrom(this.target.GetType())) { try { object returnValue = callMessage.MethodBase.Invoke(this.target, invocation.Arguments); return(input.CreateMethodReturn(returnValue, invocation.Arguments)); } catch (TargetInvocationException ex) { // The outer exception will always be a reflection exception; we want the inner, which is // the underlying exception. return(input.CreateExceptionMethodReturn(ex.InnerException)); } } else { return(input.CreateExceptionMethodReturn( new InvalidOperationException(Resources.ExceptionAdditionalInterfaceNotImplemented))); } }); return(((TransparentProxyMethodReturn)result).ToMethodReturnMessage()); }
public override IMessage Invoke(IMessage msg) { Guard.ArgumentNotNull(msg, "msg"); IMethodCallMessage callMessage = (IMethodCallMessage)msg; if (callMessage.MethodBase.DeclaringType == typeof(IInterceptingProxy)) { return HandleInterceptingProxyMethod(callMessage); } TransparentProxyMethodInvocation invocation = new TransparentProxyMethodInvocation(callMessage, target); IMethodReturn result = this.interceptorsPipeline.Invoke( invocation, delegate(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { if (callMessage.MethodBase.DeclaringType.IsAssignableFrom(target.GetType())) { try { object returnValue = callMessage.MethodBase.Invoke(target, invocation.Arguments); return input.CreateMethodReturn(returnValue, invocation.Arguments); } catch (TargetInvocationException ex) { // The outer exception will always be a reflection exception; we want the inner, which is // the underlying exception. return input.CreateExceptionMethodReturn(ex.InnerException); } } else { return input.CreateExceptionMethodReturn( new InvalidOperationException(Resources.ExceptionAdditionalInterfaceNotImplemented)); } }); return ((TransparentProxyMethodReturn)result).ToMethodReturnMessage(); }