Follow @RoyOsherove on Twitter

Custom Attributes are goodness

Well, Iv'e been generating some code for a nice little project ive been working on, and one of the features of the product (I hope to talk about this in a future post) is that it allows plugins to generate custom trace messages to be used in a client.

The client uses and processes the trace messages using reflection (i.e Each message can have totally different properties, and it's up to the client to handle the changes).  I wanted to allow the plugin creator to mark some or all of the public properties of a message as invisible. So i went ahead and created a "VisiblePropertyAttribute"  class, which marks if a field should be explicitly processed by the client. The client then recieves the message object and uses Type.GetCustomAttributes() to loop though all the attributes on a property and check whether it needs processing.

What can i say. I love this. this is soo elegant. I wonder if there is  such a feature in other languages. 


Search in RSS feeds - ROOGLE

A cool macro to ease your NUnit boilerplate woes