I need to do some stuff with parameteres passed into my method. How can I play with them (modify) using PostSharp ?
How to modify method arguments using PostSharp?
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();
}
}
© 2022 - 2024 — McMap. All rights reserved.