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); }))); }
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); } }))); }
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())))); }
static public Advisor Returning(this Advisor.IAfter @this, Expression advice) { return(@this.Returning(_Execution => advice)); }