CSharp C# Stack output of method that called your method
This is a simple example of using the StackFrame to
determine the name of the method that called the current method.
Also consider:
using System;
using System.Diagnostics;
namespace GetCallingMethod
{
class Program
{
static void Main(string[] args)
{
FirstCaller();
Console.WriteLine();
Console.ReadLine();
}
private static void FirstCaller()
{
CalledNow();
}
private static void CalledNow()
{
Console.WriteLine("Called by:{0}", new StackFrame(1, true).GetMethod().Name);
}
}
}
|
No comments:
Post a Comment