public static void TryValidateParam(decimal value, decimal minimumValue, decimal maximumValue, string paramName, string message = "") { if (value.IsInRange(minimumValue, maximumValue) == false) { message = CreateExceptionMessage(message, Resources.NumberNotInRange); ExceptionThrower.ThrowArgumentOutOfRangeException(paramName, message); } }
public static void TryValidateParam([NotNull] Enum value, string paramName, string message = "") { if (Enum.IsDefined(value.GetType(), value) == false) { message = CreateExceptionMessage(message, Resources.TheValueIsNotDefinedInTheEnumeration); ExceptionThrower.ThrowArgumentOutOfRangeException(paramName, message); } }
public static void TryValidateParam(IEnumerable collection, int size, string paramName, string message = "") { TryValidateParam(collection, paramName, message); if (collection.Count() != size) { message = CreateExceptionMessage(message, Resources.CollectionSizeIsNotValid); ExceptionThrower.ThrowArgumentOutOfRangeException(paramName, message); } }
public static void TryValidateParam(string value, StringType stringType, int minimumLength, int maximumLength, string paramName, string message = "") { //TODO: Add more string types. TryValidateParam(value, paramName, message); TryValidateParam(stringType, nameof(stringType), Resources.InvalidStringType); if (value.Length.IsInRange(minimumLength, maximumLength) == false) { message = CreateExceptionMessage( message, string.Format( CultureInfo.CurrentCulture, Resources.InvalidStringLengthAcceptableRange, minimumLength, maximumLength)); ExceptionThrower.ThrowArgumentOutOfRangeException(paramName, message); } // Final string validation switch (stringType) { case StringType.Email: if (value.IsEmailAddress() == false) { message = CreateExceptionMessage(message, Resources.InvalidEmailAddress); ExceptionThrower.ThrowArgumentInvalidException(message, paramName); } break; case StringType.Url: if (value.IsUrl() == false) { message = CreateExceptionMessage(message, Resources.InvalidUrlAddress); ExceptionThrower.ThrowArgumentInvalidException(message, paramName); } break; case StringType.NotSet: break; default: break; } }
public static void TryValidateParam(string value, int minimumLength, int maximumLength, string paramName, string message = "") { TryValidateParam(value, paramName, message); TryValidateParam(minimumLength, 0, int.MaxValue, nameof(minimumLength)); TryValidateParam(maximumLength, 1, int.MaxValue, nameof(minimumLength)); if (value.Length.IsInRange(minimumLength, maximumLength) == false) { message = CreateExceptionMessage( message, string.Format( CultureInfo.CurrentCulture, Resources.InvalidStringLengthAcceptableRange, minimumLength, maximumLength)); ExceptionThrower.ThrowArgumentOutOfRangeException(paramName, message); } }