You can output the current method of the caller by adding an extra optional string parameter to the method with the CallerMemberName attribute.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.CompilerServices;
class Program
{
static void Main(string[] args)
{
var tickCount = Convert.ToInt64(636235303654523161) ;
var date = new DateTime(tickCount);
//Debug.WriteLine(date);
PrintMessage(date.ToString());
Console.ReadLine();
}
static void PrintMessage(string msg, [CallerMemberName] string caller = "")
{
Console.WriteLine(msg);
}
}
Because it is an optional value you don’t need to modify any callers but you can now:
- Set a breakpoint condition inside DoSomething based on the caller variable
- Output the contents of caller to a log or output window
You can also use CallerLineNumber and CallerFilePath. Also remember that constructors, finalizers and operator overloads will display their underlying method names (.ctor, op_Equals etc).