.NET - MVC 中的自定义 getter/setter
[DisplayFormat(DataFormatString = "{0:c}")]
[DataType(DataType.Currency)]
public decimal? PotentialFutureExposure
{
get { return STPData.MaximumCreditExposure; }
set
{
STPData.MaximumCreditExposure = value;
this.PotentialFutureExposureOverride = value;
}
}
public decimal? PotentialFutureExposureOverride { get; set; }
所以我有这两个属性。基本上,我希望 PotentialFutureExposureOverride
属性返回它自己的值(如果有),否则我希望它返回 PotentialFutureExposure
的值。现在,PotentialFutureExposure
在设置时设置覆盖,但由于目前的某些原因,PotentialFutureExposureOverride
仍然返回空白,即使 PotentialFutureExposure
有一个值。
谢谢。
[DisplayFormat(DataFormatString = "{0:c}")]
[DataType(DataType.Currency)]
public decimal? PotentialFutureExposure
{
get { return STPData.MaximumCreditExposure; }
set
{
STPData.MaximumCreditExposure = value;
this.PotentialFutureExposureOverride = value;
}
}
public decimal? PotentialFutureExposureOverride { get; set; }
So I have these two properties. Basically, I want the PotentialFutureExposureOverride
property to return it's own value if it has one, otherwise I want it to return the value of PotentialFutureExposure
. Now PotentialFutureExposure
sets the override when it's set, but for some reason currently, PotentialFutureExposureOverride
is still returning blank even though PotentialFutureExposure
has a value.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效吗?
Does this work?
你确定你不想要你的 getter as 吗
?
Are you sure you don't want your getter as
?
PotentialFutureExposure 并没有真正的价值。在您的代码中,STPData.MaximumCreditExposure 具有实际值。在 PotentialFutureExposure setter 中设置之前,STPData.MaximumCreditExposure 是否可能已有值?如果是这种情况,那么 PotentialFutureExposure 看起来总是有一个值。
PotentialFutureExposure doesn't really have a value. In your code, STPData.MaximumCreditExposure has the actual value. Is it possible that STPData.MaximumCreditExposure has a value before you set it in the PotentialFutureExposure setter? If that is the case, then PotentialFutureExposure will always look as if it has a value.