Wednesday, December 03, 2008

Get calling method name

To get method name that was called current method use:




System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();
System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(1);
System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
string methodName = methodBase.Name;
Console.WriteLine("Method name: "+ methodName);

No comments: