Skip to content

Instantly share code, notes, and snippets.

@rexwhitten
Created July 25, 2014 01:00
Show Gist options
  • Save rexwhitten/46855f61779fd2984994 to your computer and use it in GitHub Desktop.
Save rexwhitten/46855f61779fd2984994 to your computer and use it in GitHub Desktop.
C# Extension method to capture the current stack trace context
/// Just return a String with the Assembly, Class, and Method name that called this method.
public static String GetMethodFullName<T>(this T Instance)
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
return String.Format("{0}.{1}.{2}", methodBase.DeclaringType.Namespace, methodBase.DeclaringType.Name, methodBase.Name);
}
/// Just return the whole MethodBase with the Assembly, Class, and Method name that called this method.
public static MethodBase GetMethod<T>(this T Instance)
{
StackTrace stackTrace = new StackTrace();
StackFrame stackFrame = stackTrace.GetFrame(1);
MethodBase methodBase = stackFrame.GetMethod();
return methodBase;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment