ReSharper Possible InvalidOperationException

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); } } 

This is the line that ReSharper complains about:

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

Since I will name my checkout logic in advance, I can be sure that Systolic and Diastolic will have values ​​that I can use. Does ReSharper not see this or is complaining about something else?

Interestingly, there are no problems in this section:

 if ((this.Diastolic.Value >= 0) && (this.Systolic.Value >= 0)) { valid = true; } 
+4
source share
1 answer

ReSharpers detection capabilities of this kind have their limits. ReSharper does not recognize that calling this.IsValid is basically equivalent to this.Diastolic.HasValue && this.Systolic.HasValue regarding this problem, i.e. ReSharper searches for these checks only in the same method / property.

+6
source

All Articles