<分区>
我在一个对象中有一个方法,该方法从对象中的多个位置调用。有没有一种快速简便的方法来获取调用此流行方法的方法的名称。
伪代码示例:
public Main()
{
PopularMethod();
}
public ButtonClick(object sender, EventArgs e)
{
PopularMethod();
}
public Button2Click(object sender, EventArgs e)
{
PopularMethod();
}
public void PopularMethod()
{
//Get calling method name
}
在 PopularMethod()
中,我想查看 Main
的值,如果它是从 Main
调用的...我想如果 PopularMethod()
是从 ButtonClick
ButtonClick
”
我正在查看 System.Reflection.MethodBase.GetCurrentMethod()
但这不会给我调用方法。我查看了 StackTrace
类,但我真的不喜欢每次调用该方法时都运行整个堆栈跟踪。