Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Castle DynamicProxy interceptor change argument values?

We're using DynamicProxy in a project. I've created an interceptor for a few methods.

I know that it's possible to get the method arguments inside of a Castle.DynamicProxy.IInterceptor object.

Can an interceptor change the value of the arguments passed to a method, before calling invocation.Proceed()?


1 Answers

Yes - yes, it can.

In this case, one can use Reflection on the IInvocation.Method property to get the method parameters; the method arguments are attached directly to the invocation. Although the arguments property is a readonly value (no public setter) it's of type object[] - so its properties are writable.

Thus, an interceptor can change argument values by writing to the arguments object, using the correct index corresponding to the method parameter position.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!