simpleinjector / SimpleInjector

An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.
https://simpleinjector.org
MIT License
1.21k stars 154 forks source link

get Method Name with Arguments (Signature) #466

Closed osmanrahimi closed 6 years ago

osmanrahimi commented 7 years ago

hi . I'm using SimpleInjector in my project and I have an interceptor to Log Actions . I'm using DynamicProxy Like this Toturial

but now I need to get Method Signature Like below : SimpleService.UserService.Void DoIt(System.String, Int32)(osman, 25) how can I get this ? Thank you.

dotnetjunkie commented 7 years ago

Can you provide more context with your question. It's unclear to me what you are trying to achieve, and what the problem is.

osmanrahimi commented 7 years ago

Sorry . With Castle.core Library it's pssible to get Method Name with its arguments like this:

invocation.Method

I just wanted to know can I do this ? for getting method name and argument I used this:

public void Intercept(IInvocation invocation)
{
    var type = invocation.InvocationTarget.GetType();

    var methodName = type.Name;

    StringBuilder parameters = new StringBuilder();

    foreach (var item in invocation.GetConcreteMethod().GetParameters())
    {

        parameters.Append($"{item.Name},");

    }
    parameters.Remove(parameters.Length - 1, 1);

    var argumentsValue = string.Join(",", invocation.Arguments);
}
dotnetjunkie commented 7 years ago

Why don't you use Castle.DynamicProxy instead? See this example for instance.