Skip to content

Instantly share code, notes, and snippets.

@Warrenn
Last active January 26, 2021 10:35
Show Gist options
  • Save Warrenn/1514ae95a80ac542178a8b004fd46e96 to your computer and use it in GitHub Desktop.
Save Warrenn/1514ae95a80ac542178a8b004fd46e96 to your computer and use it in GitHub Desktop.
stackTraceSource
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