public override async Task Intercept(IInvocationAsync invocation)
        {
            try
            {
                LogInterceptStart(invocation);

                await _delays.BeforeProceed().ConfigureAwait(false);

                await invocation.Proceed().ConfigureAwait(false);

                await _delays.AfterProceed().ConfigureAwait(false);

                await LogReturnValue((dynamic)invocation.ReturnValue, invocation).ConfigureAwait(false);

                LogInterceptEnd(invocation);
            }
            catch (Exception ex)
            {
                _log.Add($"{invocation.Method.Name}:InterceptException:{ex.Message}");
                throw;
            }
            finally
            {
                _log.Freeze();
            }
        }
コード例 #2
0
        public override async Task Intercept(IInvocationAsync invocation)
        {
            // do some async work before proceed
            await Task.Yield();

            await invocation.Proceed();
        }
コード例 #3
0
        public override async Task Intercept(IInvocationAsync invocation)
        {
            // do some work before invocation
            await Task.Yield();

            // invoke
            await invocation.Proceed();

            // override the return value
            invocation.ReturnValue = (int)invocation.Arguments[0] + 1;
        }
 /// <summary>
 /// Intercepts a asynchronous method <paramref name="invocation"/>.
 /// </summary>
 /// <param name="invocation">The method invocation.</param>
 public virtual Task Intercept(IInvocationAsync invocation)
 {
     return(invocation.Proceed());
 }
 private void LogInterceptEnd(IInvocationAsync invocation)
 {
     _log.Add($"{invocation.Method.Name}:InterceptEnd");
 }
        private async Task LogReturnValue <TResult>(Task <TResult> returnValue, IInvocationAsync invocation)
        {
            var result = await returnValue;

            _log.Add($"{invocation.Method.Name}:{result}");
        }
        private async Task LogReturnValue(Task returnValue, IInvocationAsync invocation)
        {
            await returnValue;

            _log.Add($"{invocation.Method.Name}:Void");
        }