GetCurrentMethod / reflection

How can I runtime see the name of the class and the method where the program is at a given time.

public class TestClass
{
private void TestMethod()
{
   console.write("You now in class: " + );  // must print You now in class: TestClass
   console.write("You now in method: " + ); // must print You now in method: testMethod

}
}

Thx,
Jim


Answer this question

GetCurrentMethod / reflection

  • gmone

    Thanks, been looking for hours :)
    /Jim


  • Sabie

    Jim,

    Use the GetCurrentMethod() method to retreive the details of the currently executing method.



    System.Reflection.MethodInfo.GetCurrentMethod().ToString();  // Gets the method name.

    System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.ToString(); // Gets the class name.

     



    David Sandor



  • GetCurrentMethod / reflection