拥有一个空的属性类是不是很糟糕?

Cod*_*asy 2 c# reflection attributes

我创建了一个属性,用于定义哪些属性具有"特殊"数据.我的属性看起来像这样:

[AttributeUsage(AttributeTargets.Property)]
    public class TestAttribute : Attribute
    {
    }
Run Code Online (Sandbox Code Playgroud)

我不需要在类的主体中有任何东西,因为它所做的只是识别属性.这是不好的做法吗?如果是这样,有什么更好的选择?

Col*_*lin 7

不.属性经常用作标志.

采取普遍:

[Serializable]
Run Code Online (Sandbox Code Playgroud)

如果你反思它的源代码,它内部基本上是空白的(它只有一些构造函数),但它是.NET中最常用的属性之一.

对于像这样的属性也是如此[XmlIgnore].