Does using System.Reflection.MethodBase.GetCurrentMethod() in a method prevent the JIT compiler from inlining the method?

时光毁灭记忆、已成空白 提交于 2021-01-29 03:29:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!