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

it2025-02-07  11

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

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 ); }

转载于:https://www.cnblogs.com/harryhan1983/archive/2011/09/17/CurrentMethodName.html

相关资源:数据结构—成绩单生成器
最新回复(0)