This project is read-only.

How to get arguments (i.e. parameter values) during interception?

Jan 21, 2015 at 1:13 AM
I am trying to port Unity Interception to Simple Injector Interception
In Unity, the method signature IMethodInvocation that gives direct access to the arguments.

However, when I look at the code snippet here
https://simpleinjector.readthedocs.org/en/latest/InterceptionExtensions.html

I see the signature is IInvocation
I can use GetConcreteMethod and GetParameters to get the parameter name, but as far as I know, I can't get the value.

If I use the VS debugger, I can see that this information is available via
[SimpleInjector.Extensions.Interceptor.InterceptorProxy.Invocation]

and then to access the
{System.Runtime.Remoting.Messaging.Message}

to look at InArgs to get my array of arguments.

To be honest, I'm not that familiar with all of this, so was wondering how I could get to the arguments in my code given the above?

Thanks.
Jan 21, 2015 at 7:41 PM
Just add a IMethodCallMessage Message { get; } property to the IInvocation interface and you're ready to go.
Jan 21, 2015 at 9:28 PM
OK, figured it out.
I ended up add an extra property to the interface snippet, i.e.
public interface IInvocation
{
    object InvocationTarget { get; }
    object ReturnValue { get; set; }
    void Proceed();
    MethodBase GetConcreteMethod();
    IMethodCallMessage Message { get; set; } // added this
}