Thursday, November 02, 2006

Getting Caller Function Name

Sometimes it would be great to know which is the caller function for the current executing function for debugging purpose. Following code snippet shows how to get caller function name:

StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
Console.WriteLine(methodBase.Name);

No comments: