以下代码给了我一个
System.StackOverflowException {无法计算表达式,因为当前线程处于堆栈溢出状态。 }
如何在模型中定义一个依赖于其他人的字段?
public class User : IMandatoryFields
{
public byte Active
{
get
{
if (this.Active == 1 && this.LocalActive == 1 && this.GlobalActive == 1) return 1;
else return 0;
}
set { this.Active = value; }
}
}
答案 0 :(得分:3)
我认为您还需要私人财产:
public class User : IMandatoryFields
{
private byte active;
public byte Active
{
get
{
if (active == 1 && this.LocalActive.HasValue &&
this.LocalActive.Value == 1 &&
this.GlobalActive.HasValue &&
this.GlobalActive.Value== 1) return 1;
else return 0;
}
set { active = value; }
}
}
public byte? LocalActive { get; set; }
public byte? GlobalActive { get; set; }