问题
The answers and comments in the following questions provide conflicting information.
How to get the name of the current method from code
Can you use reflection to find the name of the currently executing method?
It is not mentioned in the documentation as well.
https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx
回答1:
No, the JIT compiler is free to inline the method.
You'll need to add the [MethodImpl(MethodImplOptions.NoInlining)]
to any method that calls GetCurrentMethod()
to prevent it from being inlined.
If you're only interested in the method name, CallerMemberNameAttribute is much easier to use.
来源:https://stackoverflow.com/questions/41460132/does-using-system-reflection-methodbase-getcurrentmethod-in-a-method-prevent-t