public void Intercept(IInvocation invocation)
        {
            var methodInvocation = new MethodInvocation(invocation);
            IMethodInvocationResult methodInvocationResult;

            try
            {
                methodInvocationResult = _interceptionBehavior.Intercept(methodInvocation);
            }
            catch (Exception e)
            {
                methodInvocationResult = methodInvocation.CreateExceptionResult(e);
            }

            if (ReflectionHelper.IsTask(methodInvocation.MethodInfo.ReturnType))
            {
                var actualType = methodInvocation.ActualReturnType;

                invocation.ReturnValue = actualType == typeof(void)
                    ? ReflectionHelper.ConvertInvocationResultToTask(methodInvocationResult)
                    : ReflectionHelper.ConvertInvocationResultToTask(actualType, methodInvocationResult);
            }
            else
            {
                invocation.ReturnValue = methodInvocationResult.GetReturnValueOrThrow();
            }
        }
        public void Intercept(IInvocation invocation)
        {
            var methodInvocation = new MethodInvocation(invocation);
            IMethodInvocationResult methodInvocationResult;
            try
            {
                methodInvocationResult = _interceptionBehavior.Intercept(methodInvocation);
            }
            catch (Exception e)
            {
                methodInvocationResult = methodInvocation.CreateExceptionResult(e);
            }

            if (ReflectionHelper.IsTask(methodInvocation.MethodInfo.ReturnType))
            {
                var actualType = methodInvocation.ActualReturnType;

                invocation.ReturnValue = actualType == typeof(void)
                    ? ReflectionHelper.ConvertInvocationResultToTask(methodInvocationResult)
                    : ReflectionHelper.ConvertInvocationResultToTask(actualType, methodInvocationResult);
            }
            else
            {
                invocation.ReturnValue = methodInvocationResult.GetReturnValueOrThrow();
            }
        }
        public void Intercept(IInvocation invocation)
        {
            var methodInvocation = new MethodInvocation(invocation);
            var methodInvocationResultTask = _interceptionBehavior.InterceptAsync(methodInvocation);

            if (!ReflectionHelper.IsTask(methodInvocation.MethodInfo.ReturnType))
            {
                var methodInvocationResult = ReflectionHelper.GetTaskResult(methodInvocationResultTask);

                invocation.ReturnValue = methodInvocationResult.GetReturnValueOrThrow();
            }
            else
            {
                var actualReturnType = methodInvocation.ActualReturnType;
                invocation.ReturnValue = actualReturnType == typeof(void)
                    ? ReflectionHelper.ConvertInvocationResultToTask(methodInvocationResultTask)
                    : ReflectionHelper.ConvertInvocationResultToTask(actualReturnType,
                        methodInvocationResultTask);
            }
        }
Exemple #4
0
        public void Intercept(IInvocation invocation)
        {
            var methodInvocation           = new MethodInvocation(invocation);
            var methodInvocationResultTask = _interceptionBehavior.InterceptAsync(methodInvocation);

            if (!ReflectionHelper.IsTask(methodInvocation.MethodInfo.ReturnType))
            {
                var methodInvocationResult = ReflectionHelper.GetTaskResult(methodInvocationResultTask);

                invocation.ReturnValue = methodInvocationResult.GetReturnValueOrThrow();
            }
            else
            {
                var actualReturnType = methodInvocation.ActualReturnType;
                invocation.ReturnValue = actualReturnType == typeof(void)
                    ? ReflectionHelper.ConvertInvocationResultToTask(methodInvocationResultTask)
                    : ReflectionHelper.ConvertInvocationResultToTask(actualReturnType,
                                                                     methodInvocationResultTask);
            }
        }
        public void Intercept(IInvocation invocation)
        {
            var methodInvocation = new MethodInvocation(invocation, _interceptionBehaviors);

            var methodInvocationResultTask = methodInvocation.InvokeNextAsync();

            var returnType = methodInvocation.MethodInfo.ReturnType;

            if (ReflectionHelper.IsTask(returnType))
            {
                invocation.ReturnValue = ReflectionHelper.IsNonGenericTask(returnType)
                    ? ReflectionHelper.ConvertInvocationResultToTask(methodInvocationResultTask)
                    : ReflectionHelper.ConvertInvocationResultToTask(methodInvocation.ActualReturnType,
                                                                     methodInvocationResultTask);
            }
            else
            {
                var methodInvocationResult = ReflectionHelper.GetResultFromTask(methodInvocationResultTask);
                invocation.ReturnValue = methodInvocationResult.GetReturnValueOrThrow();
            }
        }