Created
July 25, 2014 01:00
-
-
Save rexwhitten/46855f61779fd2984994 to your computer and use it in GitHub Desktop.
C# Extension method to capture the current stack trace context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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