6. Attribute 6.1 What is the property? There are minimal type .NET properties. The first category I call it Metadata property - it allows some data to be attached to the class or method. These data are numbered as part of the Metadata, and can be accessed by mapping like other Metadata classes. Another property of Metadata is [Serializable], which is attached to the class, indicating that the instance of the class can be serialized. [Serializable] Public class ctest {} Another type of attribute is context properties. The properties of the context type use and Metadata similar syntax, but they are actually different. The context type attribute provides an interpretation mechanism that can be pre-processed and / or subsequently processed by this mechanism. If you know the General Brown's General Brown, you might be familiar with this idea. 6.2 Can I create my own metadata properties? Yes it is. Simply export a class from System.attribute and tag it as an AttributeUSAGE property. For example: [AttributeUSAGETS.CLASS] PUBLIC CLASS INSPIREDBYATTRIBUTE: system.attribute {public string inspiredby
Public InspiredByattribute (String Inspiredby) {INSPIREDBY = Inspiredby;}}
[InspiredBy ( "Andy Mc's brilliant .NET FAQ")] class CTest {} class CApp {public static void Main () {object [] atts = typeof (CTest) .GetCustomAttributes (); foreach (object att in atts) if ( ATT IS ISPIREDBYATTRIBUTE) Console.writeline ("Class Ctest Was Inspired By {0}", _ (InspiredByattribute); {}}