|
tribute),而该特性类仅被用于类和方法上。
DefectTrackAttribute定义的代码如下:
using System;
namespace MyAttributeClasses { [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,AllowMultiple = true)] public class DefectTrackAttribute :Attribute { private string cDefectID ; private DateTime dModificationDate ; private string cDeveloperID ; private string cDefectOrigin ; private string cFixComment ;
public DefectTrackAttribute () {
}
public DefectTrackAttribute( string lcDefectID, string lcModificationDate, string lcDeveloperID ) { this.cDefectID = lcDefectID ; this.dModificationDate = System.DateTime.Parse( lcModificationDate ) ; this.cDeveloperID = lcDeveloperID ; }
public string DefectID { get { return cDefectID ; } }
public string ModificationDate { get { return dModificationDate.ToShortDateString() ; } }
public string DeveloperID { get { return cDeveloperID ; } }
public string Origin { get { return cDefectOrigin ; } set { cDefectOrigin = value ; } }
public string FixComment { get { return cFixComment ; } set { cFixComment = value ; } }
} }
如果你之前没有接触过特性,那么你将对下面的代码有点陌生。
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,AllowMultiple = true)]
这一行代码,把特性[AttributeUsage]附加到特性类的定义上。方括号的语法表明一个特 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页
|