You can use StackTraceand StackFrame. You can get an entire stack trace by calling the constructor StrackTraceor just a specific stack of the stack using the constructor StackFrame, which accepts the number of skipped frames.
You should be aware that this may not be accurate due to the attachment. (method e..g In method B, which calls your method - method A will be reported, not B).
Code example:
using System;
using System.Diagnostics;
class Test
{
static void ShowCaller()
{
StackFrame frame = new StackFrame(1);
Console.WriteLine(frame.GetMethod());
}
static void Intermediate()
{
ShowCaller();
}
static void Main()
{
Intermediate();
}
}
, Void Main() - Intermediate(), Void Intermediate().
( , . , , .)