HARRY's Tech Blog

 

如何获取当前运行的方法名称

取得实例类名称的字符串表示:

this.GetType().Name

取得当前运行的函数的名称 :

System.Reflection.MethodInfo.GetCurrentMethod().Name

或者

System.Diagnostics.StackFrame().GetMethod().Name

取得调用当前运行方法的方法的名称

System.Reflection;
using System.Diagnostics;
private static void WhoCallMe()
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
Console.WriteLine( " Parent Method Name {0} \n", methodBase.Name );
}

posted on 2011-09-17 11:53  Harry Han  阅读(656)  评论(0编辑  收藏  举报

导航