c# - 如何获取当前函数的名称?

标签 c# .net system.reflection

<分区>

Possible Duplicate:
Can you use reflection to find the name of the currently executing method?
C# how to get the name of the current method from code

例如:

void foo() {
    Console.Write(__MYNAME__);
}

打印:foo

可以用 C# 实现吗?

最佳答案

试试这个:

System.Reflection.MethodBase.GetCurrentMethod().Name 

关于c# - 如何获取当前函数的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10130504/

相关文章:

c# - FieldInfo 更新字段的子字段

c# - System.Reflection.Assembly 的空引用异常

C# SocketAsyncEventHandler 在 Complete 上评估操作

c# - 获取异常 : The Size Property Has an Invalid Size Of 0

.net - WCF 双工服务和 TCP 端口耗尽

asp.net - 提供旧文件的 Azure Web 应用程序

c# - 如何使用自定义卸载程序卸载 Windows 服务

c# - 如何在 .NET Core 中发出类型

c# - 使用 C# 的 SqlConnection 错误 vs2015

c# - 与我将它作为 Windows 应用程序运行时相比,WebMethod() 在每次执行时都很慢