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);
    }

```

猜你喜欢

转载自www.cnblogs.com/wesson2019-blog/p/11972394.html
今日推荐