Last active
January 26, 2021 10:35
-
-
Save Warrenn/1514ae95a80ac542178a8b004fd46e96 to your computer and use it in GitHub Desktop.
stackTraceSource
This file contains hidden or 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
private static Type GetCallingType() | |
{ | |
var stack = new StackTrace(); | |
var currentType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType; | |
var callingType = currentType; | |
var frames = stack.GetFrames() ?? new StackFrame[] { }; | |
foreach (var frame in frames) | |
{ | |
var method = frame.GetMethod(); | |
callingType = method.DeclaringType ?? currentType; | |
if (callingType != currentType) break; | |
} | |
return callingType; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment