在方法中使用 System.Reflection.MethodBase.GetCurrentMethod() 是否会阻止 JIT 编译器内联该方法? [英] Does using System.Reflection.MethodBase.GetCurrentMethod() in a method prevent the JIT compiler from inlining the method?
问题描述
以下问题中的答案和评论提供了相互矛盾的信息.
The answers and comments in the following questions provide conflicting information.
文档中也没有提及.
https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx
推荐答案
不,JIT 编译器可以自由地内联方法.
No, the JIT compiler is free to inline the method.
您需要将 [MethodImpl(MethodImplOptions.NoInlining)]
添加到任何调用 GetCurrentMethod()
的方法中,以防止其被内联.
You'll need to add the [MethodImpl(MethodImplOptions.NoInlining)]
to any method that calls GetCurrentMethod()
to prevent it from being inlined.
如果您只对方法名称感兴趣,CallerMemberNameAttribute
更容易使用.
If you're only interested in the method name, CallerMemberNameAttribute
is much easier to use.
这篇关于在方法中使用 System.Reflection.MethodBase.GetCurrentMethod() 是否会阻止 JIT 编译器内联该方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!