예제 #1
0
        public IMethodReturn Invoke(IMethodInvocation invocation, GetNextInterceptorHandler getNext)
        {
            int i = (int)invocation.Arguments[0].Value * 2;

            invocation.Arguments[0].Value = i;
            return(getNext()(invocation, getNext));
        }
 private async Task WrapNoReturnTask(IMethodInvocation input, GetNextInterceptorHandler getNext)
 {
     using (var scope = new TransactionScope(ScopeOption, CreateTransactionOptions(), TransactionScopeAsyncFlowOption.Enabled))
     {
         await(Task) getNext()(input, getNext).ReturnValue;
         scope.Complete();
     }
 }
        public IMethodReturn Invoke(IMethodInvocation invocation, GetNextInterceptorHandler getNext)
        {
            var result = getNext()(invocation, getNext);

            if (result.Exception == null)
            {
                int output = (int)result.Outputs[0].Value * 3;
                result.Outputs[0].Value = output;
            }
            return(result);
        }
 public IMethodReturn Invoke(IMethodInvocation invocation, GetNextInterceptorHandler getNext)
 {
     using (var scope = new TransactionScope(ScopeOption, CreateTransactionOptions()))
     {
         var ret = getNext()(invocation, getNext);
         if (ret.Exception == null)
         {
             scope.Complete();
         }
         return(ret);
     }
 }
        /// <summary>
        /// Execute interceptor processing.
        /// </summary>
        /// <param name="invocation">Inputs to the current call to the target.</param>
        /// <param name="getNext">Delegate to execute to get the next delegate in the interceptor chain.</param>
        /// <returns>Return value from the target.</returns>
#if Net451
        public IMethodReturn Invoke(IMethodInvocation invocation, GetNextInterceptorHandler getNext)
        {
            var method = (MethodInfo)invocation.Method;

            if (method.ReturnType == typeof(Task))
            {
                return(invocation.CreateMethodReturn(WrapNoReturnTask(invocation, getNext)));
            }
            if (method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                var methodReturn = _genericWrapperMethod.MakeGenericMethod(method.ReturnType.GetGenericArguments()[0])
                                   .Invoke(this, new object[] { invocation, getNext });
                return(invocation.CreateMethodReturn(methodReturn));
            }
            using (var scope = new TransactionScope(ScopeOption, CreateTransactionOptions()))
            {
                var ret = getNext()(invocation, getNext);
                if (ret.Exception == null)
                {
                    scope.Complete();
                }
                return(ret);
            }
        }