Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return the function name?

Tags:

c#

.net

oop

I wrote a class and I want to return the names of function which I implemented inside the class.

public class cls
{
    public static string fun()
    {
      //code
    }
}

Simply I want to know how to know the name of the function (which is fun), not the return value of that function.

like image 449
Amged Avatar asked Apr 10 '26 03:04

Amged


1 Answers

public static void TraceContext(string messageFormat)
{
    Trace.WriteLine(string.Format(messageFormat, 
        new System.Diagnostics.StackFrame(1).GetMethod().Name));
}

See How To: Obtain Method Name Programmatically For Tracing

like image 193
Marcelo Assis Avatar answered Apr 12 '26 20:04

Marcelo Assis