Why is it that attributes are proclaimed as first class citizens in .NET, when they are not really treated that way.
You have no way of querying attributes, without having to resort to reflection. They can't be generic (yeah, there are reasons, but come on!), and you can't use them as generic constraints.
There might be a lot of other downsides to attributes, but the most annoying must be, that you can't easily query them. Of course, you can just create an extension method and you're done, but it just seems like they've gotten the cold treatment in .NET.
If they was real first class citizens, you'd have better language integration ie.
if(SomeClass hasattribute MyAttribute) { ... } or if a type has an attribute, it should be directly accessible as in SomeClass.MyAttribute.AttributeProperty.
I know there are a lot of issues regarding the implementation of attributes, that make the above impossible (at least for the current version of C#), but attributes are incredibly useful and deserve a lot more attention, outside the reflection box.
No comments:
Post a Comment