public FieldValidationOutput CompareStrings(string s1, string s2) { var result = new FieldValidationOutput(); result.IsValid = (s1 == s2); result.ErrorMessage = $"{s1} {(result.IsValid ? "==" : "!=")} {s2}"; return(result); }
public FieldValidationOutput CompareDoubles(double d1, double d2, string errorMsgIfDifferent) { // comparing doubles can produce unexpected results. // to understand more: https://floating-point-gui.de/errors/comparison/ var result = new FieldValidationOutput(); result.IsValid = NearlyEqual(d1, d2, 0.0001); if (!result.IsValid) { if (string.IsNullOrWhiteSpace(errorMsgIfDifferent)) { result.ErrorMessage = $"Values are different: {d1.ToString()}, {d2.ToString()}"; } else { result.ErrorMessage = errorMsgIfDifferent; } } return(result); }