我有一个员工班:
public class Employee
{
public string Name { get; set; }
public Int32 Salary { get; set; }
public DateTime DateOfBirth { get; set; }
}
我创建了一个自定义CustomeAttribute
属性
public class CustomAttributes : Attribute
{
public int Sequence {set;get;}
public int Length { set; get; }
}
我在 as 中使用asCustomAttribute
属性Employee
public class Employee
{
public string Name { get; set; }
public Int32 Salary { get; set; }
public DateTime DateOfBirth { get; set; }
}
public class Employee
{
[CustomAttributes(Sequence=1,Length=10)]
public string Name { get; set; }
[CustomAttributes(Sequence = 2, Length= 6)]
public Int32 Salary { get; set; }
[CustomAttributes(Sequence =3, Length = 8)]
public DateTime DateOfBirth { get; set; }
}
我想验证每个属性定义都应该存在属性集合。如果我将新属性添加Age
到“员工”为
public class Employee
{
[CustomAttributes(Sequence=1,Length=10)]
public string Name { get; set; }
[CustomAttributes(Sequence = 2, Length= 6)]
public Int32 Salary { get; set; }
[CustomAttributes(Sequence =3, Length = 8)]
public DateTime DateOfBirth { get; set; }
public int Age {get;set;}
}
由于缺少属性,我应该得到编译时错误。这将确保将属性值写入该类的每个属性以及来自同一程序集的类。??
对于没有属性值的属性,我应该得到编译时错误。