Just derive a class from “System.Attribute” and mark it with the “AttributeUsage” attribute. The script that I have mentioned will definitely help you.
For example:
Code:[AttributeUsage(AttributeTargets.Class)] public class InspiredByAttribute : System.Attribute { public string InspiredBy; public Inspired By Attribute( string inspiredBy ) { InspiredBy = inspiredBy; } } [InspiredBy(".NET FAQ")] class CTest{} class Capp { public static void Main() { object[] atts = typeof(CTest).GetCustomAttributes(true); foreach( object att in atts ) if( att is InspiredByAttribute ) Console.WriteLine( "Class CTest was inspired by {0}", ((InspiredByAttribute)att).InspiredBy); } }



Reply With Quote

Bookmarks