public static void CheckIsValidNumber <T>(T d, params object[] mesageArgs) { if (d == null) { throw new NullReferenceException(Integrity.getMessage(nullPointerDefaultMessage, mesageArgs)); } }
/// <summary> /// Checks whether an object is null, and if so raises an exception with a default message or one built from passed in message params /// </summary> /// <param name="obj">The object to check for nullness.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="NullReferenceException">Raised if obj is null</exception> public static void CheckNotNull(object obj, params object[] mesageArgs) { if (obj == null) { throw new NullReferenceException(Integrity.getMessage(nullPointerDefaultMessage, mesageArgs)); } }
/// <summary> /// Checks whether a condition is true, if not raises an InvalidOperationException, whose message is either a default message, or built from passed in message params /// </summary> /// <param name="condition">The condition to check is true.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="InvalidOperationException">Raised if condition is false</exception> public static void Check(bool condition, params object[] mesageArgs) { if (!condition) { string text = Integrity.getMessage(defaultMessage, mesageArgs); throw new InvalidOperationException(text); } }
/// <summary> /// Checks whether a string is null or zero length. If so, raises an exception with a default message or one built from passed in message params /// </summary> /// <param name="s">The string to check for nullness or zero length.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="NullReferenceException">Raised if s is null</exception> /// <exception cref="InvalidOperationException">Raised if s is exactly 0 characters long</exception> /// <remarks> /// Note that an exception is only raised if the string has exactly zero length; a string with a single space (for example) would be fine /// </remarks> public static void CheckStringNotNullOrEmpty(string s, params object[] mesageArgs) { if (s == null) { throw new NullReferenceException(Integrity.getMessage(nullPointerDefaultMessage, mesageArgs)); } if (s.Length == 0) { string text = Integrity.getMessage(emptyStringDefaultMessage, mesageArgs); throw new InvalidOperationException(text); } }
/// <summary> /// Checks whether a number is NaN, +Infinity, -Infinity. If so, raises an exception with a default message or one built from passed in message params /// </summary> /// <param name="d">The number to check for NaN, or +/-Infinity.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="InvalidOperationException">Raised if d is NaN, +/-Infinity</exception> public static void CheckIsValidNumber(double d, params object[] mesageArgs) { if (Double.IsNaN(d)) { throw new InvalidOperationException(Integrity.getMessage(nanDefaultMessage, mesageArgs)); } if (Double.IsPositiveInfinity(d)) { throw new InvalidOperationException(Integrity.getMessage(pInfinityDefaultMessage, mesageArgs)); } if (Double.IsNegativeInfinity(d)) { throw new InvalidOperationException(Integrity.getMessage(nInfinityDefaultMessage, mesageArgs)); } }
/// <summary> /// Checks whether a number is NaN, +Infinity, -Infinity. If so, raises an exception with a default message or one built from passed in message params /// </summary> /// <param name="d">The number to check for NaN, or +/-Infinity.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="InvalidOperationException">Raised if d is NaN, +/-Infinity</exception> public static void CheckIsValidNumber(float d, params object[] mesageArgs) { if (float.IsNaN(d)) { string text = Integrity.getMessage(nanDefaultMessage, mesageArgs); throw new InvalidOperationException(text); } if (float.IsPositiveInfinity(d)) { string text = Integrity.getMessage(pInfinityDefaultMessage, mesageArgs); throw new InvalidOperationException(text); } if (float.IsNegativeInfinity(d)) { string text = Integrity.getMessage(nInfinityDefaultMessage, mesageArgs); throw new InvalidOperationException(text); } }
/// <summary> /// Checks whether a number is NaN, +Infinity, -Infinity or null. If so, raises an exception with a default message or one built from passed in message params /// </summary> /// <param name="d">The number to check for NaN, null, or +/-Infinity.</param> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="NullReferenceException">Raised if d is null</exception> /// <exception cref="InvalidOperationException">Raised if d is NaN, +/-Infinity</exception> public static void CheckIsValidNumber(double?d, params object[] mesageArgs) { if (d == null) { throw new NullReferenceException(Integrity.getMessage(nullPointerDefaultMessage, mesageArgs)); } double nonNullD = (double)d; if (Double.IsNaN(nonNullD)) { throw new InvalidOperationException(Integrity.getMessage(nanDefaultMessage, mesageArgs)); } if (Double.IsPositiveInfinity(nonNullD)) { throw new InvalidOperationException(Integrity.getMessage(pInfinityDefaultMessage, mesageArgs)); } if (Double.IsNegativeInfinity(nonNullD)) { throw new InvalidOperationException(Integrity.getMessage(nInfinityDefaultMessage, mesageArgs)); } }
/// <summary> /// Raises an InvalidOperationException, whose message is either a default message, or built from passed in message params /// </summary> /// <param name="mesageArgs">See the documentation for deferredStringBuilder to see how the message is built.</param> /// <exception cref="InvalidOperationException"></exception> public static void Fail(params object[] mesageArgs) { string text = Integrity.getMessage(defaultMessage, mesageArgs); throw new InvalidOperationException(text); }