【发布时间】:2009-02-16 20:11:55
【问题描述】:
有没有办法规定一个类的客户应该为一个类中的一组属性指定一个值。例如(见下面的代码),我可以规定应在编译时指定就业类中的“EmploymentType”属性吗?我知道我可以使用参数化构造函数等。我专门寻找在编译期间输出自定义警告或错误。这可能吗?
public class Employment
{
public EmploymentType EmploymentType {get; set;}
}
public enum EmploymentType
{
FullTime = 1,
PartTime= 2
}
public class Client
{
Employment e = new Employment();
// if i build the above code, i should get a error or warning saying you should specify value for EmploymentType
}
【问题讨论】:
标签: c# .net compiler-construction clr