none
I want to get the function name i'm currently in,how can it be done RRS feed

  • Question

  • Hello , i want to get the function name like this:

    functionname

    {

        string strfunctionname = getTheFunctionName();

    }

    How can this be done, thanks a lot.

    Saturday, March 31, 2012 5:59 AM

Answers

  • .Net provide StackTrace class by which you can achive it. Code sample as below.

    StackTrace st = new StackTrace();
    StackFrame sf = st.GetFrame(0);
    MethodBase currentMethodName = sf.GetMethod();
    string methodname = currentMethodName.Name;
    For C# programing language you can refer .NET Base Class Library forum for prompt response.


    Lingaraj Mishra

    • Marked as answer by Genrge Wednesday, April 11, 2012 1:38 AM
    Monday, April 2, 2012 5:39 PM

All replies

  • .Net provide StackTrace class by which you can achive it. Code sample as below.

    StackTrace st = new StackTrace();
    StackFrame sf = st.GetFrame(0);
    MethodBase currentMethodName = sf.GetMethod();
    string methodname = currentMethodName.Name;
    For C# programing language you can refer .NET Base Class Library forum for prompt response.


    Lingaraj Mishra

    • Marked as answer by Genrge Wednesday, April 11, 2012 1:38 AM
    Monday, April 2, 2012 5:39 PM
  • Hi, Mishra, thanks a lot,this might work,but would please give me a method in C++. it would be greate if you might use template.

    Tuesday, April 10, 2012 12:28 PM
  • For language specific question you can move your question to Visual C++ Language Forum for prompt response as this question is specific to Architecture.


    Lingaraj Mishra

    Tuesday, April 10, 2012 4:18 PM
  • using System.Reflection;
    
    void Foo()
    {
        Debug.Print("Calling method "{0}", MethodBase.GetCurrentMethod().Name);
    }


    Wednesday, April 11, 2012 2:52 PM