I just saw a blog post from Alex Mueller about marker interfaces and C# attributes and which way you should be using them.
I, for one, believe that attributes are far the best way to mark a class instead of using an empty marker interface. Why? Well, there are several good reasons to use attributes over interfaces, especially when it comes to inheritance. That aside, attributes are also a lot more flexible than interfaces.
So why don’t people use attributes more often? The most common complaint is that interfaces are easier to use and check for in code (I.e. interfaces requires less code). But I think this is mainly because people don’t know where to look for help in the framework. So I’ve devised 30 extension methods that will make your work with attributes a little bit easier and strongly typed.
Now you can check for the existence of an attribute like this:
Well, I hope someone can use this… Any thoughts or criticisms for the code will be greatly appreciated. Otherwise, enjoy! ;)
6 comments: