Caller Information Attributes调用者信息特性

这些信息有助于跟踪、调试和创建诊断工具。

if the call site doesn't provide the argument, the compiler will use the current file, line number, or member name to fill in the argument instead of taking the normal default value. if the caller does supply an argument, the compiler will leave it alone.

如果调用点不提供参数,编译器将使用当前文件、行号或成员名来填充实参,而不是使用正常的默认值。如果调用者确实提供了一个参数,编译器将不处理它。

  • CallerFilePathAttribute 包含调用者的源文件(编译时)的完整路径。
  • CallerLineNumberAttribute 调用方法在源文件中的行号。
  • CallerMemberNameAttribute 调用者的方法或属性名称。
static void Main(string[] args)
{
    ......
    voidTraceMessage();
}
static void TraceMessage(string msg = null, [CallerFilePath] string file = null, [CallerLineNumber] int line = 0, [CallerMemberName] string member = null)
{
    Console.WriteLine(msg + " {0}: {1} - {2}", file, line, member);
}

posted @   wesson2019  阅读(139)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示