[Name ("Chinese name","Nicholas Tse"), Name ("English name","Nic")]
Public ClassStudent {}
Public ClassSchool {
[Name ("Chinese name","Nicholas Tse"), Name ("English name","Nic")]
Public StringSchoolname {get {Return "Niuqiang University";}}
}
[Attributeusage (attributetargets. All, allowmultiple =True)]
Public ClassName: system. Attribute
{
Public StringKey {Get; set ;}
Public StringValue {Get; set ;}
PublicName (StringKey,String Value){
Key = key;
Value =Value;
}
}
// Obtain the features of the class
VaR attrs = attribute. getcustomattributes (Typeof(Student ));
Response. Write ("<Br>");
Response. Write ("Class features");
Foreach(VAR itemInAttrs)
{
VaR t = (name) item;
Response. Write ("<Br>");
Response. Write (T). Key +":"+ T. Value +","+ T. typeid. tostring ());
}
// Obtain the attributes. This is also true for methods, fields, and other features.
VaR properties =Typeof(School). getproperties ();
Response. Write ("<Br>"); Response. Write ("<Br>");
Response. Write ("Attributes have");
Foreach(VAR itemInProperties)
{
Foreach(VAR ATTRInItem. getcustomattributes (False))
{
VaR t = (name) ATTR;
Response. Write ("<Br>");
Response. Write (T). Key +":"+ T. Value +","+ T. typeid. tostring ());
}
}
In this way, we get an instance of the name class at runtime. The name attribute is output.