UseAttrib: RemarkAttribute : .
RemarkAttribute . comment RemarkAttribute () . , . , , ..
, . , . '
, , , .
, . . , . , .
[attrib (__,
__1 = , __2 = ,...)]
, . .
. , , .
. RemarkAttribute, Supplement, .
[AttributeUsage(AttributeTargets.All)] public class RemarkAttribute: Attribute {
string pri_remark; // Remark
// , public string Supplement;
public RemarkAttribute(string comment) { pri_remark = comment;
Supplement = "";
}
public string Remark { get {
Return pri_remark;
}
}
}
, Supplement "". . Supplement RemarkAttribute, , .
[RemarkAttribute(" .",
Supplement = " .")] class UseAttrib {
//...
}
|
|
RemarkAttribute. , , , Supplement, . , ,), -, . , . : , , .
, Supplement .
// .
Using System;
Using System.Reflection;
[AttributeUsage(AttributeTargets.All)] public class RemarkAttribute: Attribute {
string pri_remark; // Remark
public string Supplement; //
public RemarkAttribute(string comment) { pri_remark = comment;
Supplement = "";
}
public string Remark { get {
Return pri_remark;
}
}
}
[RemarkAttribute(" .",
Supplement = " .")] class UseAttrib {
//...
}
class NamedParamDemo { static void Main() {
Type t = typeof(UseAttrib);
Console.Write(" " + t.Name + ": "); object[] attribs = t.GetCustomAttributes(false); foreach(object in attribs) {
Console.WriteLine (o);
}
// RemarkAttribute.
Type tRemAtt = typeof(RemarkAttribute);
RemarkAttribute ra = (RemarkAttribute)