Exemple #1
0
 public override void OnInvoke(MethodInterceptionArgs args)
 {
     args.Proceed();
     for (int i = 0; i < args.Arguments.Count; i++)
     {
         if (args.Arguments[i] is int) args.Arguments[i] = -1;
     }
 }
        public InterceptionAspectGenerator(object instance, BindingRestrictions rule,
            IEnumerable<MethodInterceptionAspect> aspects, MethodInfo method,
            IEnumerable<DynamicMetaObject> args, IEnumerable<Type> argsTypes)
        {
            _rule = rule;
            _aspects = aspects;
            _originalArgs = args;
            var argsValues = args.Select(x => x.Value).ToArray();
            _isRetValue = method.ReturnType != typeof(void);
            _isByRefArgs = argsTypes.Any(t => t.IsByRef);

            if (_isByRefArgs)
            {
                if (_isRetValue) _aspectArgs = new FuncInterceptionRefArgs(instance, method, argsValues, DelegateFactory.CreateDelegate(instance, method));
                
                else _aspectArgs = new ActionInterceptionRefArgs(instance, method, argsValues, DelegateFactory.CreateDelegate(instance, method));
            }
            else
            {
                if (_isRetValue) _aspectArgs = new FuncInterceptionArgs(instance, method, argsValues, DelegateFactory.CreateFunction(instance, method));
                
                else _aspectArgs = new ActionInterceptionArgs(instance, method, argsValues, DelegateFactory.CreateMethodCall(instance, method));
            }
        }
Exemple #3
0
 public override void OnInvoke(MethodInterceptionArgs args)
 { }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if ((int)args.Arguments[0] < 0) Console.WriteLine("The first argument is less then 0 and we will not invoke " + args.Method.Name);

            else args.Proceed();
        }
        public override void OnInvoke(MethodInterceptionArgs args)
        {
            if (args.Arguments.Any(arg => arg == null)) Console.WriteLine("\n" + args.Method + " can't be called because some of args is null");

            else args.Proceed();
        }
 /// <summary>
 /// Method invoked instead of the method to which the aspect has been applied.
 /// </summary>
 /// <param name="args">Method arguments including return value and all necessary info.</param>
 public virtual void OnInvoke(MethodInterceptionArgs args)
 {
     args.Proceed();
 }