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);
}
分类:
C# in Dept
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律