Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
默认属性列表应该出现在c#.net中我的类定义中_.net_Attributes_Propertydescriptor - Fatal编程技术网

默认属性列表应该出现在c#.net中我的类定义中

默认属性列表应该出现在c#.net中我的类定义中,.net,attributes,propertydescriptor,.net,Attributes,Propertydescriptor,我有一个雇员类: public class Employee { public string Name { get; set; } public Int32 Salary { get; set; } public DateTime DateOfBirth { get; set; } } 我创建了一个自定义属性CustomeAttributeas public class CustomAttributes : Attribute {

我有一个雇员类:

public class Employee
{

        public string Name { get; set; }
        public Int32 Salary { get; set; }
        public DateTime DateOfBirth { get; set; }
}
我创建了一个自定义属性
CustomeAttribute
as

public class CustomAttributes : Attribute
{

        public  int Sequence {set;get;}
        public  int Length { set; get; }

}
我正在使用
CustomAttribute
作为
Employee
as中的属性

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
添加到“员工”as

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;}
}
我应该得到编译时错误,因为属性丢失。这将确保写作 该类的每个属性以及来自同一程序集的类的属性值


我应该为没有属性值的属性获取编译时错误。

无法为此生成编译时错误。但是,您可以在单元测试或
#debug
构建中使用反射进行操作-只需迭代属性,检查
属性.IsDefined(property,typeof(CustomAttributes))