gpt4 book ai didi

c# - ReSharper 可能的 InvalidOperationException

转载 作者:太空狗 更新时间:2023-10-29 20:22:00 25 4
gpt4 key购买 nike

public class BloodPressure {
public Int16? Diastolic { get; set; }

private Boolean IsValid {
get {
var valid = false;

if (this.Diastolic.HasValue && this.Systolic.HasValue) {
if ((this.Diastolic.Value >= 0) && (this.Systolic.Value >= 0)) {
valid = true;
}
}

return (valid);
}
}

public Int16? Systolic { get; set; }

public override String ToString() {
var result = "";

if (this.IsValid) {
result = this.Systolic.Value.ToString("0") + "/" + this.Diastolic.Value.ToString("0");
}
else {
result = null;
}

return (result);
}
}

这是 ReSharper 提示的行:

result = this.Systolic.Value.ToString("0") + "/" + this.Diastolic.Value.ToString("0");

因为我事先调用了我的验证逻辑,所以我可以确定 Systolic 和 Diastolic 都具有我可以使用的值。 ReSharper 没有看到这一点,还是在提示其他事情?

有趣的是,这部分没有问题:

if ((this.Diastolic.Value >= 0) && (this.Systolic.Value >= 0)) {
valid = true;
}

最佳答案

ReSharpers 检测此类内容的能力有其局限性。 ReSharper 不承认调用 this.IsValid 基本上等同于 this.Diastolic.HasValue && this.Systolic.HasValue 关于那个问题,即 ReSharper 看起来仅在相同的方法/属性中进行那些检查。

关于c# - ReSharper 可能的 InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5952532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com