C# 正在添加';属性';对属性类名进行了破坏性更改?

C# 正在添加';属性';对属性类名进行了破坏性更改?,c#,.net,attributes,C#,.net,Attributes,我遇到了以下C#代码: 我们使用SonarLint,其中一个表示类应该以单词属性作为前缀 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] public class MarkerAttribute : Attribute { } 我想知道将名称标记更改为标记属性是一个突破性的改变吗?因为在使用属性时,您可以跳过属性部分。另一方面,当在代码中使用该属性时,您需要完整的名称,这样它就不

我遇到了以下C#代码:

我们使用SonarLint,其中一个表示类应该以单词
属性
作为前缀

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class 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“标记”在“标记”和“标记属性”之间不明确; 使用“@Marker”或“MarkerAttribute”


属性是元数据。凭他们自己的属性什么也做不了。当一些代码读取属性时,属性变得很有用。为了读取属性值,代码应该使用属性类名。例如,通过电话:


然后,您将得到完全相同的SonarLint规则被破坏-您将得到两个属性类,其中一个将是不符合的。

从API的角度来看,这当然是一个破坏性的更改,因为每个类都重命名了。因此,您还必须重新编译所有依赖的程序集。
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class MarkerAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class Marker : MarkerAttribute { }
Maker maker = yourType.GetCustomAttribute<Maker>();
public class Marker : MarkerAttribute { }