Function name under execution
-
Hi! How can i find out the name of function which is under execution. For example, please see the following code: void TestFunction() { String currentFunctionName = "TestFunction"; } In the above code, i've hardcoded the name of function in variable currentFunctionName. I want to do that programatically. Please tell me how can i do so. Back during the days of C+, i use __FUNCTION__, please tell me how can i do this is C#. Is it an area of reflection ?
Imtiaz
-
Hi! How can i find out the name of function which is under execution. For example, please see the following code: void TestFunction() { String currentFunctionName = "TestFunction"; } In the above code, i've hardcoded the name of function in variable currentFunctionName. I want to do that programatically. Please tell me how can i do so. Back during the days of C+, i use __FUNCTION__, please tell me how can i do this is C#. Is it an area of reflection ?
Imtiaz
StackTrace st = new StackTrace();
string methodName = st.GetFrame(0).GetMethod().Name;
I'm largely language agnostic
After a while they all bug me :doh:
-
Hi! How can i find out the name of function which is under execution. For example, please see the following code: void TestFunction() { String currentFunctionName = "TestFunction"; } In the above code, i've hardcoded the name of function in variable currentFunctionName. I want to do that programatically. Please tell me how can i do so. Back during the days of C+, i use __FUNCTION__, please tell me how can i do this is C#. Is it an area of reflection ?
Imtiaz
string currentMethod = MethodInfo.GetCurrentMethod().Name;