How can I require an attribute on a class definition?

Posted by spoulson on Stack Overflow See other posts from Stack Overflow or by spoulson
Published on 2010-05-24T17:26:59Z Indexed on 2010/05/24 17:31 UTC
Read the original article Hit count: 246

Filed under:
|

Is there a way to enforce a compile requirement for certain attributes on a class or interface implementation?

For example, let's say my application uses a series of static classes that contain const int resource values. I'd like to decorate the class in a Description attribute to describe its contents. In concept, I'd like to apply this attribute requirement to an interface, then each static class would implement it with its required Description. I could write a run-time check or a unit test to check compliance. But really a compile-time check would be best.

Is there such a thing?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about attributes