I want to have the name of the current Handler being called.
MethodInfo.GetCurrentMethod().Name
or MethodBase.GetCurrentMethod().Name
work fine in debug mode.
But once I obfuscate (using confuserEx) my project the 2 functions return "System.Reflection.MethodBase ()"
.
I've noticed I could get the name of my function using the following line :
((RoutedEventHandler)this.MyMethodName).GetMethodInfo().Name
It returns "MyMethodName"
which is the expected result.
But it's not generic at all. I'd like a piece of code working when I don't know the current method's name.
getMethodName() method returns the name of the method containing the execution point represented by this stack trace element. Thread. currentThread().
The MethodInfo class represents a method of a type. You can use a MethodInfo object to obtain information about the method that the object represents and to invoke the method.
As stated here:
Caller Info values are emitted as literals into the Intermediate Language (IL) at compile time. Unlike the results of the StackTrace property for exceptions, the results aren't affected by obfuscation.
So from your method you could try to call the following method like:
public string GetCaller([System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
return memberName;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With