C# 5.0-.Net新特性
调用者信息特性
CallerMemberNameAttribute | CallerFilePathAttribute | CallerLineNumberAttribute
.NET Framework 4.5 中新增,用于请求编译器在编译过程中进行代码的转换 。
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。使用方式:直接调用即可
public static void TraceMessage(string message, string errCode, [CallerMemberNameAttribute] string memberName = "", [CallerFilePathAttribute] string filePath = "", [CallerLineNumberAttribute] int lineNumber = 0)
若要在 .NET Framework 4.0 中使用,需自定义特性
namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] public class CallerMemberNameAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )] public class CallerFilePathAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false )] public class CallerLineNumberAttribute : Attribute { } }

更多精彩