从被调用函数获取调用函数名称 [英] Get the calling function name from the called function

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

问题描述

可能重复:
如何找到调用当前方法的方法方法?

如何从C#中的被调用函数中获取调用函数名称?

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天全站免登陆