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

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

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-08-01
  • 2021-08-29
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-04-06
  • 2022-03-08
  • 2021-07-28
相关资源
相似解决方案