C# 5.0 給我們帶來了三個非常有用的編譯器特性
CallerMemberName
CallerFilePath
CallerLineNumber
在C與C++中由下列字符幫助我們實現調試消息的文件行號
在.NET 4中與其功能相等的是
在C#5.0中我們可以用以下代碼實現調試信息文件行號獲取:
三個特性是.NET 4.5里面的,如果在.NET4中使用那么請定義一下特性:
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public class CallerFilePathAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
public class CallerLineNumberAttribute : Attribute { }
}
新聞熱點
疑難解答