How to modify method arguments using PostSharp?
Asked Answered
S

1

10

I need to do some stuff with parameteres passed into my method. How can I play with them (modify) using PostSharp ?

Sosthena answered 19/12, 2011 at 21:46 Comment(0)
T
17

Using methodinterception, you can use the Args.Arguments object to change the values via the SetArgument method.

[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();
    }       
}
Tibold answered 19/12, 2011 at 21:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.