CODECUBE VENTURES

Calling Method Name

Here's a nifty way of getting the name of whatever method called the method you're currently in. Good for app logging utilities.

using System.Diagnostics;

...

StackTrace st = new StackTrace(2);
StackFrame sf = st.GetFrame(1);
string msg = string.Format("{0}.{1}",
sf.GetMethod().DeclaringType.FullName,
sf.GetMethod().Name);

Latest post: Digging Up the First Version of CodeCube

See more in the archives