Example #1
0
 public override void OnEntry(MethodExecutionArgs args)
 {
     for (int i = 0; i < args.Arguments.Count; i++)
     {
         if (args.Arguments[i] is int) args.Arguments[i] = -1;
         else if (args.Arguments[i] is string) args.Arguments[i] = "I changed your value";
     }
 }
        public BoundaryAspectGenerator(object instance, DynamicMetaObject metaObj, IEnumerable<OnMethodBoundaryAspect> aspects,
            MethodInfo method, IEnumerable<DynamicMetaObject> args, IEnumerable<Type> argsTypes)
        {
            _rule = metaObj.Restrictions;

            var methExecArgs = new MethodExecutionArgs(instance, method, new Arguments(args.Select(x => x.Value).ToArray()));

            _aspectCalls = new AspectCalls(metaObj.Expression, aspects, args, methExecArgs, argsTypes.Any(t => t.IsByRef));
        }
 /// <summary>
 /// Method executed after the body of method to which this aspect is applied, 
 /// but only when the method successfully returns.
 /// </summary>
 /// <param name="args">Method arguments including return value and all necessary info.</param>
 public virtual void OnSuccess(MethodExecutionArgs args)
 {
 }
 /// <summary>
 /// Method executed after the body of method to which this aspect is applied
 /// (this method is invoked from the finally block, it's mean that this method will be invoked in any way).
 /// This is a good place where to log the return value, inform other applications that the method has finished the execution.
 /// </summary>
 /// <param name="args">Method arguments including return value and all necessary info.</param>
 public virtual void OnExit(MethodExecutionArgs args)
 {
 }
 /// <summary>
 /// When an exception is happened then this method will be called.
 /// This is a perfect place to log the error messages in an generic way and do something useful with that information.
 /// </summary>
 /// <param name="args">Method arguments including return value and all necessary info.</param>
 public virtual void OnException(MethodExecutionArgs args)
 {
 }
 /// <summary>
 /// Method executed before the body of method to which this aspect is applied.
 /// OnEntry method is a perfect place where to implement the logic such as input parameters logging, caching, authentication/authorization.
 /// </summary>
 /// <param name="args">Method arguments including return value and all necessary info.</param>
 public virtual void OnEntry(MethodExecutionArgs args)
 {
 }
Example #7
0
 public override void OnEntry(MethodExecutionArgs args)
 {
     var entity = (TestEntity)args.Arguments[0];
     entity.Name = "ChangedName";
     entity.Number = 999;
 }
            public AspectCalls(Expression origMethod, IEnumerable<OnMethodBoundaryAspect> aspects, IEnumerable<DynamicMetaObject> args, MethodExecutionArgs methExecArgs, bool isByRefArgs)
                : this()
            {
                _origMethod = origMethod;
                _args = args;
                MethodExecutionArgs = methExecArgs;
                _isByRefArgs = isByRefArgs;

                ArgsExpression = Expression.Constant(methExecArgs);
                RetMethodValue = Expression.Parameter(typeof(object));

                foreach (var aspect in aspects)
                {
                    EntryCalls.Add(GenerateCall("OnEntry", aspect));
                    SuccessCalls.Add(GenerateCall("OnSuccess", aspect));
                    ExceptionCalls.Add(GenerateCall("OnException", aspect));
                    ExitCalls.Add(GenerateCall("OnExit", aspect));
                }

                OriginalCall = GenerateOriginalCall();
            }