如何在运行时从方法中找到调用方法的方法名称?
例如:
Class A
{
M1()
{
B.M2();
}
}
class B
{
public static M2()
{
// I need some code here to find out the name of the method that
// called this method, preferably the name of the declared type
// of the calling method also.
}
}
Run Code Online (Sandbox Code Playgroud)
Tho*_*ing 10
你可以试试:
using System.Diagnostics;
StackTrace stackTrace = new StackTrace();
Console.WriteLine(stackTrace.GetFrame(1).GetMethod().Name);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |