如何使用PostSharp修改方法参数?

Ton*_*ony 10 c# postsharp

我需要做一些传递给我的方法的参数.如何使用PostSharp玩它们(修改)?

Dus*_*vis 17

使用methodinterception,您可以使用Args.Arguments对象通过SetArgument方法更改值.

[Serializable]
public class MyAspect : MethodInterceptionAspect
{
    public override void OnInvoke(MethodInterceptionArgs args)
    {
        string input = (string)args.Arguments[0];

        if (input.Equals("123"))
        {
            args.Arguments.SetArgument(0, " 456");
        }

        args.Proceed();
    }       
}
Run Code Online (Sandbox Code Playgroud)