Existing struct
<textarea readonly name="code" class="csharp">Public struct DESC <br/>{< br/> private byte val1; <br/> [description ("one attribute")] <br/> Public byte des <br/>{< br/> get {return val1 ;}< br/> set {val1 = value ;} <br/>}</P> <p> ///... omitted below <br/>}</textarea> Get description Code : String STR = ""; <br/> DESC = new DESC (); </P> <p> // do not use reflection to obtain attributes. <br/> propertydescriptor Pd = typedescriptor. getproperties (typeof (DESC) ["des"]; <br/> descriptionattribute description = Pd = NULL? Null: PD. attributes [typeof (descriptionattribute)] as descriptionattribute; <br/> STR = Description = NULL? "": Description. description; </P> <p> // obtain attributes using reflection <br/> propertyinfo Pi = typeof (DESC ). getproperty ("des"); <br/> foreach (Object OBJ in pi. getcustomattributes (false) <br/>{< br/> If (obj is descriptionattribute) <br/> STR = (OBJ as descriptionattribute ). description; <br/>}</P> <p> // you do not need to reflect the properties of the struct. <br/> attributecollection attributes = typedescriptor. getattributes (DESC); // or typeof (DESC) <br/> descriptionattribute da = (descriptionattribute) attributes [typeof (descriptionattribute)]; <br/> If (attributes. contains (DA) <br/> STR = da. description; </P> <p> // obtain the features of the struct Using Reflection. <br/> type mytype = typeof (DESC ); <br/> foreach (Object OBJ in mytype. getcustomattributes (false) <br/>{< br/> If (obj is descriptionattribute) <br/> STR = (OBJ as descriptionattribute ). description; <br/>}