【发布时间】:2017-05-31 23:22:33
【问题描述】:
这有点与这个问题相切:
Retrieving the calling method name from within a method
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, ButtonClick, Button2Click]
更新:C# reflection and finding all references 是我要找的!哇!谢谢大家
【问题讨论】:
-
当然 - Visual Studio 中的静态分析工具和其他第 3 方工具可以做到这一点。不过,框架中没有内置任何内容。
-
@D Stanley 我想这些工具会解析实际代码并可以通过这种方式定位声明/用法。我想知道您为什么要以编程方式执行此操作?
-
解决方案应该类似于这个one。
标签: c# reflection