seesharper / LightInject.Interception

LightInject.Interception supports Aspect Oriented Programming through proxy-based method interceptors.
11 stars 7 forks source link

Add property to access, in IInvocationInfo, the underlying target class method, if the proxy is an interface. #18

Closed leandro86 closed 5 years ago

leandro86 commented 5 years ago

Hi!

I was trying to address this issue: https://github.com/seesharper/LightInject.Interception/issues/17

It seemed to me that it would be nice to have access, inside IInvocationInfo, to the target method of the concrete class, if the proxy is an interface: like Castle's Dynamic proxy allows to do (see property MethodInvocationTarget on https://github.com/castleproject/Core/blob/master/src/Castle.Core/DynamicProxy/IInvocation.cs).

With this change, now I can test, inside the interceptor, for a custom attribute in the class:

public class MySimpleInterceptor : IInterceptor
{
    public object Invoke(IInvocationInfo invocationInfo)
    {
        bool hasCustomAttribute = invocationInfo.MethodInvocationTarget.GetCustomAttribute<MyCustomAttribute>() != null;
        // ...           
    }
}

I doubt my implementation is correct: let me know if there's something that it could be done better.

Thanks!

seesharper commented 5 years ago

Thanks 👍

seesharper commented 5 years ago

@leandro86 FYI I have changed the name to TargetMethod. Version 2.0.2 has been pushed to NuGet and should be available when the package is validated 👍

leandro86 commented 5 years ago

Great! I wasn't really sure about the name myself.