本文介绍了获得从调用函数中调用函数名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能调用函数的名字从被调用函数在C#?

解决方案

 新的StackFrame(1,真).GetMethod()。名称
 

请注意,在发布版本的编译器可能会内联方法被调用,在这种情况下,上述code将返回调用者的调用者,所以为了安全起见,你应该装点您的方法:

  [MethodImpl(MethodImplOptions.NoInlining)
 

How can I get the calling function name from the called function in c#?

解决方案
new StackFrame(1, true).GetMethod().Name

Note that in release builds the compiler might inline the method being called, in which case the above code would return the caller of the caller, so to be safe you should decorate your method with:

[MethodImpl(MethodImplOptions.NoInlining)]

这篇关于获得从调用函数中调用函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 15:21
查看更多