Exemplo n.º 1
0
        public void Calling(CallingInterceptContext callingInterceptorContext)
        {
            if (_logger == null)
            {
                _logger = App.GetService <ILoggerFactory>().CreateLogger(callingInterceptorContext.Owner.GetType().Name);
            }

            _logger.LogInformation($"{callingInterceptorContext.MethodName} invoking, arguments: {(callingInterceptorContext.Parameters == null || callingInterceptorContext.Parameters.Length <= 0 ? string.Empty : callingInterceptorContext.Parameters.ToJsonString())}");
        }
Exemplo n.º 2
0
        public InterceptResult CallingIntercepts(object owner, object[] parameters, Type returnType, string methodName)
        {
            if (owner == null)
            {
                throw new System.ArgumentNullException(nameof(owner));
            }

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

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

            foreach (var callingInterceptor in CallingInterceptors)
            {
                callingInterceptor.Calling(context);
                if (context.HasResult)
                {
                    return(new InterceptResult
                    {
                        HasResult = true,
                        Result = context.Result
                    });
                }
            }

            return(new InterceptResult
            {
                HasResult = false
            });
        }
 public override void Calling(CallingInterceptContext callingInterceptorContext)
 {
     Console.WriteLine("Calling in " + callingInterceptorContext.Owner.ToString());
 }
Exemplo n.º 4
0
 public override void Calling(CallingInterceptContext callingInterceptorContext)
 {
     Debug.WriteLine("Calling in " + callingInterceptorContext.Owner.ToString());
     //callingInterceptorContext.HasResult = true;
     //callingInterceptorContext.Result = "test";
 }