How to get the name of current function?

48,713

Solution 1

Try this:

System.Reflection.MethodBase.GetCurrentMethod().Name 

Solution 2

You can check the stack trace

using System.Diagnostics;

// get call stack
StackTrace stackTrace = new StackTrace();

// get calling method name
Console.WriteLine(stackTrace.GetFrame(0).GetMethod().Name);

But beware, if the method is inlined you get the parent method name.

Share:
48,713
Jack
Author by

Jack

Computer lover. :-) -- I'm not a native speaker of the english language. So, if you find any mistake what I have written, you are free to fix for me or tell me on. :)

Updated on September 11, 2020

Comments