【发布时间】:2014-09-10 05:09:02
【问题描述】:
如何在委托方法中获取委托名称?
这是我的测试程序:
namespace Test
{
class Program
{
public Action action;
void real()
{
// I hoped it would output "action" here, but it was "real"
Console.WriteLine(MethodInfo.GetCurrentMethod().Name);
}
public Program()
{
action = real;
}
static void Main(string[] args)
{
Program pr = new Program();
pr.action();
}
}
}
那么我怎样才能得到委托的名称action 而不是方法read?
我试过MethodInfo.GetCurrentMethod(),但没用。
【问题讨论】:
-
action是委托而不是方法,real是委托方法。 -
来自
void DoAction(Action actionParam),应该给action还是actionParam? -
@Hassan Nisar,感谢指正,我会更新说明。
-
@Henk Holterman,对不起,我不明白你的意思,你能补充一些细节吗?