Index: Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityHelper.cs =================================================================== diff -u -r974fb1eadbd8a630c7a992648ad42ac85ec205b1 -r320fc1268c48766797d895a8f4ace546f35bf64c --- Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityHelper.cs (.../ProbabilityHelper.cs) (revision 974fb1eadbd8a630c7a992648ad42ac85ec205b1) +++ Ringtoets/Common/src/Ringtoets.Common.Data/Probability/ProbabilityHelper.cs (.../ProbabilityHelper.cs) (revision 320fc1268c48766797d895a8f4ace546f35bf64c) @@ -38,32 +38,56 @@ /// Checks whether the given is valid. /// /// The probability to check. - /// Optional: false is should - /// be considered a valid value. Default is true. + /// Optional: true is should + /// be considered a valid value. Default is false. /// true when is valid; false otherwise. - public static bool IsValidProbability(double probability, bool nanIsValid = false) + public static bool IsValidProbability(double probability, bool isNaNValid = false) { - if (nanIsValid && double.IsNaN(probability)) + if (isNaNValid && double.IsNaN(probability)) { return true; } return probabilityValidityRange.InRange(probability); } /// - /// Checks if a argument is a valid probability value. + /// Checks if an argument is a valid probability value. /// /// The value to be validated. /// The name of the argument. - /// Optional: false is should - /// be considered a valid value. Default is true. + /// Optional: true is should + /// be considered a valid value. Default is false. /// Thrown when /// is not a valid probability value. - public static void ValidateProbability(double probability, string paramName, bool nanIsValid = false) + public static void ValidateProbability(double probability, string paramName, bool isNaNValid = false) { - if (!IsValidProbability(probability, nanIsValid)) + ValidateProbability(probability, paramName, Resources.Probability_Must_be_in_Range_0_, isNaNValid); + } + + /// + /// Checks if an argument is a valid probability value. + /// + /// The value to be validated. + /// The name of the argument. + /// The custom message containing an insertion points + /// (specifically {0}) for the validity range of . + /// Optional: true is should + /// be considered a valid value. Default is false. + /// Thrown when + /// is not a valid probability value. + /// Thrown when + /// doesn't contain a '{0}' insertion location for the range used to validate . + public static void ValidateProbability(double probability, string paramName, string customMessage, bool isNaNValid = false) + { + if (!customMessage.Contains("{0}")) { - string message = string.Format(Resources.Probability_Must_be_in_Range_0_, + throw new ArgumentException("The custom message should have a insert location (\"{0}\") where the validity range is to be inserted.", + nameof(customMessage)); + } + + if (!IsValidProbability(probability, isNaNValid)) + { + string message = string.Format(customMessage, probabilityValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture)); throw new ArgumentOutOfRangeException(paramName, message); }