get caller member name,caller file path,caller line number via attributes

using System.Runtime.CompilerServices;

static void AttributesDemo([CallerMemberName] string memberName = null, [CallerFilePath] string filePath = null, [CallerLineNumber] int lineNumber=0)
        {
            Console.WriteLine(memberName);
            Console.WriteLine(filePath);
            Console.WriteLine(lineNumber);
        }

 

posted @ 2020-04-19 22:40  FredGrit  阅读(112)  评论(0编辑  收藏  举报