user677526
user677526

Reputation:

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()?

Upvotes: 3

Views: 2175

Answers (1)

user677526
user677526

Reputation:

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.

Upvotes: 6

Related Questions