1
我碰到下面的C#代碼:是否將「屬性」添加到屬性類名中作爲重大更改?
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class Marker : Attribute
{
}
我們使用SonarLint和一個of it's rules是說,該類應與字Attribute
前綴。
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class MarkerAttribute : Attribute
{
}
我想知道是改變名稱Marker
到MarkerAttribute
重大更改?由於使用該屬性時,您可以跳過Attribute
部分。另一方面,當在代碼中使用屬性時,你需要全名,所以它會被打破。
如果這被認爲是一個突變,那麼最好的方法是什麼?因爲這樣的:使用時
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class MarkerAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class Marker : MarkerAttribute { }
會給以下編譯錯誤:
CS1614 '標記' 是 '標記' 和 'MarkerAttribute' 之間不明確; 使用'@Marker'或'MarkerAttribute'
從API的角度來看,它當然是一個突破性的變化,就像每個*類重命名一樣。因此,您必須重新編譯所有依賴程序集。 – HimBromBeere