How can I get the name of the calling function in C#?

前端 未结 3 1147
独厮守ぢ
独厮守ぢ 2020-12-11 12:33

I need to get the name of the calling function in C#. I read about stackframe method but everywhere its said its not reliable and hurts the performance.

But I need i

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 13:31

    You can do something like:

     var stackTrace = new StackTrace();
     var name = stackTrace.GetFrame(1).GetMethod().Name;
    

    and it work with any version of the framework/language.

提交回复
热议问题