我知道你能做到

this.GetType().FullName

得到

My.Current.Class

但我该打什么电话

My.Current.Class.CurrentMethod

当前回答

这样不行吗?

System.Reflection.MethodBase.GetCurrentMethod()

返回一个表示当前执行方法的MethodBase对象。 名称空间:系统。反射 程序集:mscorlib(在mscorlib.dll中)

http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx

其他回答

using System.Diagnostics;
...

var st = new StackTrace();
var sf = st.GetFrame(0);

var currentMethodName = sf.GetMethod();

或者,如果你想要一个helper方法:

[MethodImpl(MethodImplOptions.NoInlining)]
public string GetCurrentMethod()
{
    var st = new StackTrace();
    var sf = st.GetFrame(1);

    return sf.GetMethod().Name;
}

更新到@ stussmith。

我认为获得全名的最好方法是:

 this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;

或者试试这个

string method = string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name);   

调用System.Reflection.MethodBase.GetCurrentMethod()。方法中的名称。

这样不行吗?

System.Reflection.MethodBase.GetCurrentMethod()

返回一个表示当前执行方法的MethodBase对象。 名称空间:系统。反射 程序集:mscorlib(在mscorlib.dll中)

http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getcurrentmethod.aspx

System.Reflection.MethodBase.GetCurrentMethod()。Name不是一个很好的选择,因为它只显示方法名而没有其他信息。

类似于string MyMethod(string str),上述属性将只返回MyMethod,这是不够的。

最好使用System.Reflection.MethodBase.GetCurrentMethod().ToString(),它将返回整个方法签名…