以下问题中的答案和评论提供了相互矛盾的信息。
如何从代码中获取当前方法的名称 https://stackoverflow.com/questions/2652460/how-to-get-the-name-of-the-current-method-from-code
您可以使用反射来查找当前正在执行的方法的名称吗? https://stackoverflow.com/questions/44153/can-you-use-reflection-to-find-the-name-of-the-currently-executing-method
文档中也没有提及。
https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx https://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx
不,JIT 编译器可以自由内联该方法。
您需要添加[MethodImpl(MethodImplOptions.NoInlining)]
任何调用的方法GetCurrentMethod()
以防止其被内联。
如果您只对方法名称感兴趣,CallerMemberNameAttribute https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute(v=vs.110).aspx使用起来更加方便。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)