protected void InterceptNoResult(Action action, MethodBase method, object[] arguments) { var ctx = new InterceptorContext(action) { Method = method, Arguments = arguments }; using (_interceptorFactory(ctx)) { if (ctx.Exception != null) { ExceptionDispatchInfo.Capture(ctx.Exception).Throw(); } } }
protected T Intercept <T>(Func <T> func, MethodBase method, object[] arguments) { var ctx = new InterceptorContext(() => (object)func()) { Method = method, Arguments = arguments, ReturnType = typeof(T) }; using (_interceptorFactory(ctx)) { if (ctx.Exception != null) { ExceptionDispatchInfo.Capture(ctx.Exception).Throw(); } if (!ctx.Canceled) { return((T)ctx.ReturnValue); } } return(default(T)); }