C# 5.0 CallerMemberName CallerFilePath CallerLineNumber获取调用方法名称,路径,行号

时间:2024-08-04 08:04:55
    class Program
{
static void Main(string[] args)
{
Log("测试");
Console.Read();
} public static void Log(string msg,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = )
{
string msgToLog = string.Format("{0} ({1} line {2}): {3}",
memberName, filePath, lineNumber, msg);
Console.WriteLine(msgToLog);
}
}

C# 5.0 CallerMemberName CallerFilePath CallerLineNumber获取调用方法名称,路径,行号