使用的System.Reflection获取一个方法的全名 [英] Using System.Reflection to Get a Method's Full Name
本文介绍了使用的System.Reflection获取一个方法的全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似如下的类:
I have a class that look like the following:
public class MyClass
{
...
protected void MyMethod()
{
...
string myName = System.Reflection.MethodBase.GetCurrentMethod.Name;
...
}
...
}
MYNAME
的值为的MyMethod。
The value of myName
is "MyMethod".
有没有办法,我可以使用反射来获取MyClass.MyMethod的值的方法 MYNAME
呢?
Is there a way that I can use Reflection to get a value of "MyClass.MyMethod" for myName
instead?
推荐答案
您可以看看 ReflectedType
的 MethodBase
从 GetCurrentMethod
,即
MethodBase method = System.Reflection.MethodBase.GetCurrentMethod();
string methodName = method.Name;
string className = method.ReflectedType.Name;
string fullMethodName = className + "." + methodName;
这篇关于使用的System.Reflection获取一个方法的全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文