1
如何在Micro Framework中查看當前方法名稱?我知道這兩個選項,但它們是針對Windows框架:在Micro Framework中查看當前方法名稱
1.
MethodBase method = (new StackTrace(true)).GetFrame(0).GetMethod();
string methodname = method.DeclaringType.FullName + "." + method.Name;
2.
MethodBase method = MethodInfo.GetCurrentMethod();
string methodname = method.DeclaringType.FullName + "." + method.Name;
編輯:還有另外一種方法,但既不作品在微框架:
3.
using System.Diagnostics;
// get call stack
StackTrace stackTrace = new StackTrace();
// get calling method name
Console.WriteLine(stackTrace.GetFrame(1).GetMethod().Name);
爲什麼你需要這個? – 2012-01-10 18:13:56
我正在處理日誌保護程序類。 – Manu 2012-01-10 18:18:34
我已經添加了一個新的方法,既沒有效果。 – Manu 2012-01-11 09:52:16