Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify method arguments using PostSharp?

Tags:

c#

postsharp

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

like image 910
Tony Avatar asked Dec 19 '11 21:12

Tony


1 Answers

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();
    }       
}
like image 153
Dustin Davis Avatar answered Sep 20 '22 12:09

Dustin Davis