Adding metadata to your types: Attributes
At the recent Toronto Code Camp, I attended a very interesting session, “Building Plug-ins and Inspecting Classes with Reflection”, by Shawn Hayward. In his presention he talked about how developers can utilize reflection to save coding and make programs extensible. He used three cases to drive his presentation, “Dynamic Method Invocation”, “Attributes”, and “Plugins”.
I especially enjoyed the treatment he provided on Attributes. Using attributes, you can “tag” a class or its members with simple fixed arbitrary data. The attributes are manifested in your assemblies as metadata that is ignored by the .Net framework and to be utilized, you must do your own processing. To read the attribute values you must use reflection. Examples of attributes can be foudn throughout the .Net framework: web services, xml serialization, object serialization, and custom tool support.