Exemplo n.º 1
0
 static public Advisor Returning(this Advisor.IAfter @this, Action <ILGenerator> advise)
 {
     return(@this.Returning(new Action <MethodBuilder>(_Method =>
     {
         var _body = _Method.GetILGenerator();
         advise(_body);
         _body.Emit(OpCodes.Ret);
     })));
 }
Exemplo n.º 2
0
        static public Advisor Returning(this Advisor.IAfter @this, Func <Advisor.Execution.Returning, Expression> advise)
        {
            var _signature = @this.Generator.Method.GetParameters().Select(_Parameter => Expression.Parameter(_Parameter.ParameterType));

            return(@this.Returning(new Action <MethodBuilder>(_Method =>
            {
                if (@this.Generator.Method.IsStatic)
                {
                    Expression.Lambda(advise(new Advisor.Execution.Returning(@this.Generator.Method, null, new Collection <Expression>(_signature))), _signature).CompileToMethod(_Method);
                }
                else
                {
                    var _instance = Expression.Parameter(@this.Generator.Method.DeclaringType);
                    Expression.Lambda(advise(new Advisor.Execution.Returning(@this.Generator.Method, _instance, new Collection <Expression>(_signature))), new ParameterExpression[] { _instance }.Concat(_signature)).CompileToMethod(_Method);
                }
            })));
        }
Exemplo n.º 3
0
 static public Advisor Returning(this Advisor.IAfter @this, Action advice)
 {
     return(@this.Returning(Expression.Call(Expression.Field(null, Aspect.Module.DefineField(advice)), Metadata <Action> .Method(_Action => _Action.Invoke()))));
 }
Exemplo n.º 4
0
 static public Advisor Returning(this Advisor.IAfter @this, Expression advice)
 {
     return(@this.Returning(_Execution => advice));
 }