I have created an attribute which will define which properties have "special" data. My Attribute looks something like this:
[AttributeUsage(AttributeTargets.Property)]
public class TestAttribute : Attribute
{
}
I don't need anything in the body of the class because all it's doing is identifying the properties. Is this bad practice? If so, what are better alternatives?
No. Attributes are frequently used just as flags.
Take the pervasive:
[Serializable]
If you reflect into its source code, it's basically blank inside (it just has some constructors), but it's one of the most used attributes in .NET.
The same thing goes for attributes like [XmlIgnore]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With