========================================= Document. CS
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication2 {[attributeusage (attributetargets. property, // The range to which this feature can be applied (only for properties) allowmultiple = true, // whether multiple applications can be applied to the same item inherited = true) // If a feature is applied to a class or interface, it is automatically applied to all derived classes or interfaces.] // If a feature is applied to a property or method, public class documentattribute: attribute {private string m_strname; private bool m_blnisyes; Public bool isyes {get {return m_blnisyes ;} set {m_blnisyes = value;} public documentattribute (string p_name) {This. m_strname = p_name ;}}}
=================================== Main program
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication2 {class program {// specify the feature [document ("Document 1", // the value required by the constructor isyes = true)] // optional parameter (document class attribute) Public string name {Get; set;} static void main (string [] ARGs ){}}}
This article is from the "programmer's home-Hunter" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1569008
Write custom features