C# 获取调用某个函数的函数列表 [英] C# get a list of functions that call a certain function
本文介绍了C# 获取调用某个函数的函数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是这个问题的一个切线:
This is kind of a tangent to this question:
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]
Is it possible to use reflection to get a list of functions that call upon the "PopularMethod" function in it's body? Ie: [Main, ButtonClick, Button2Click]
更新:C# 反射和查找所有引用正是我要找的!哇!谢谢大家
Update: C# reflection and finding all references Was what I was looking for! woot! Thank you all
推荐答案
您可以使用一个属性让运行时服务为您获取此信息:
There is an attribute you can use to let the runtime services get this information for you:
public void PopularMethod([System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
{
}
这篇关于C# 获取调用某个函数的函数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文