Пример #1
0
 public void Called(CalledInterceptContext calledInterceptorContext)
 {
     if (calledInterceptorContext.ReturnValue != null)
     {
         _logger.LogInformation($"{calledInterceptorContext.MethodName} invoked, result: {calledInterceptorContext.ReturnValue.ToJsonString()}");
     }
 }
Пример #2
0
        public InterceptResult CalledIntercepts(object owner, object[] parameters, object returnValue, Type returnType, string methodName)
        {
            if (owner == null)
            {
                throw new System.ArgumentNullException(nameof(owner));
            }

            if (CalledInterceptors == null || CalledInterceptors.Count == 0)
            {
                return(new InterceptResult
                {
                    HasResult = false
                });
            }

            var context = new CalledInterceptContext
            {
                Owner       = owner,
                Parameters  = parameters,
                ReturnValue = returnValue,
                HasResult   = false,
                ReturnType  = returnType,
                MethodName  = methodName
            };

            foreach (var calledInterceptor in CalledInterceptors)
            {
                calledInterceptor.Called(context);
                if (context.HasResult)
                {
                    return(new InterceptResult
                    {
                        HasResult = false,
                        Result = context.Result
                    });
                }
            }

            return(new InterceptResult
            {
                HasResult = false
            });
        }
Пример #3
0
 public override void Called(CalledInterceptContext calledInterceptorContext)
 {
     Console.WriteLine("Called in " + calledInterceptorContext.Owner.ToString());
 }