我有这样的财产:
private Decimal _payout;
public Decimal PayoutValue
{
get { return _payout; }
set
{
_payout = value;
//second part of following conditional is an enum
if (Math.Abs(value) > 1 && this.PayoutType == CutType.Percent)
{
_payout /= 100;
}
}
}
如您所见,它取决于 的值PayoutType
,这只是一个简单的枚举属性:
public CutType PayoutType { get; set; }
我的问题是在PayoutType
设置之前似乎没有PayoutValue
设置,所以下面的条件永远不会正确。如何在评估PayoutType
之前强制设置?PayoutValue
谢谢。
更新感谢您的回答。我想我应该提到,大多数时候这个对象是通过 DataContexts 或从我的客户端(MVC 项目)的 Http.Post 绑定的,所以我真的没有任何构造函数。有没有其他方法,或者我应该开始在我的编程中发挥创意?