获得从调用函数中调用函数名 [英] Get Calling function name from Called function

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

问题描述

  

可能重复:
  <一href="http://stackoverflow.com/questions/171970/how-can-i-find-the-method-that-called-the-current-method">How我能找到调用当前方法的方法?

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

解决方案

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

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

  [MethodImpl(MethodImplOptions.NoInlining)
 

Possible Duplicate:
How can I find the method that called the current method?

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)]

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆