大家好,我想问一下如何用反射得到调用当前方法的方法名称
public void methodToBeCall()
{
//想用反射或者methodMain的名字
}public void methodMain()
{
//Call methodToBeCall
methodToBeCall();
}我的问题是,如果我在methodMain里面调用methodToBeCall方法,我想在methodToBeCall方法里面用反射来得到methodMain的名字
我知道取得当前方法名是用这个: System.Reflection.MethodBase.GetCurrentMethod().Name
但是没找到取得调用当前方法名的办法啊~
能帮一下忙么?
谢谢了!
public void methodToBeCall()
{
//想用反射或者methodMain的名字
}public void methodMain()
{
//Call methodToBeCall
methodToBeCall();
}我的问题是,如果我在methodMain里面调用methodToBeCall方法,我想在methodToBeCall方法里面用反射来得到methodMain的名字
我知道取得当前方法名是用这个: System.Reflection.MethodBase.GetCurrentMethod().Name
但是没找到取得调用当前方法名的办法啊~
能帮一下忙么?
谢谢了!
应该更改为
//想用反射获得methodMain的名字
不好意思~~~
Console.WriteLine(method.Name);