/// <summary> /// Throws <see cref="ArgumentException"/> if argument is contains <paramref name="elem"/> /// </summary> /// <exception cref="ArgumentException">Throws if argument is contains <paramref name="elem"/></exception> /// <exception cref="ArgValidationException">Throws if argument is <c>null</c></exception> public static Argument <TEnumerable> NotContains <TEnumerable, T>(this Argument <TEnumerable> arg, T elem) where TEnumerable : IEnumerable <T> { if (arg.ValidationIsDisabled()) { return(arg); } InvalidMethodArgumentThrower.IfArgumentValueIsNull(arg, methodName: nameof(NotContains)); if (arg.Value.Contains(elem)) { ValidationErrorExceptionThrower.ArgumentException(arg, $"Argument '{arg.Name}' contains {ExceptionMessageHelper.GetStringValueForMessage(elem)} value. {GetCurrentValuesString(arg.Value)}"); } return(arg); }
/// <summary> /// Throws <see cref="ArgumentException"/> if argument is <c>null</c> or argument is contains only whitespaces /// </summary> /// <exception cref="ArgumentException">Throws if argument is <c>null</c> or argument is contains only whitespaces</exception> public static Argument <string> NotNullOrWhitespace(this Argument <string> arg) { if (arg.ValidationIsDisabled()) { return(arg); } if (string.IsNullOrWhiteSpace(arg.Value)) { ValidationErrorExceptionThrower.ArgumentException(arg, $"Argument '{arg.Name}' cannot be empty or whitespace. Current value: {ExceptionMessageHelper.GetStringValueForMessage(arg.Value)}"); } return(arg); }
/// <summary> /// Throws <see cref="ArgumentException"/> if argument is ends with <paramref name="value"/> /// </summary> /// <exception cref="ArgumentException">Throws if argument is ends with <paramref name="value"/></exception> /// <exception cref="ArgValidationException">Throws if argument is <c>null</c></exception> public static Argument <string> NotEndsWith(this Argument <string> arg, string value, StringComparison comparisonType) { if (arg.ValidationIsDisabled()) { return(arg); } if (EndsWithPrivate(arg, value, comparisonType, methodName: nameof(NotEndsWith))) { ValidationErrorExceptionThrower.ArgumentException(arg, $"Argument '{arg.Name}' must not ends with {ExceptionMessageHelper.GetStringValueForMessage(value)}. Current value: {ExceptionMessageHelper.GetStringValueForMessage(arg.Value)}"); } return(arg); }
/// <summary> /// Throws <see cref="ArgumentException"/> if argument is match <paramref name="pattern"/> /// </summary> /// <exception cref="ArgumentException">Throws if argument is match <paramref name="pattern"/></exception> /// <exception cref="ArgValidationException">Throws if argument is <c>null</c> or <paramref name="pattern"/> is <c>null</c></exception> public static Argument <string> NotMatch(this Argument <string> arg, string pattern) { if (arg.ValidationIsDisabled()) { return(arg); } InvalidMethodArgumentThrower.IfArgumentValueIsNull(arg, methodName: nameof(NotMatch)); InvalidMethodArgumentThrower.IfArgumentOfMethodIsNull(arg: pattern, argName: nameof(pattern), methodName: nameof(NotMatch)); if (StringConditionChecker.Match(arg, pattern)) { ValidationErrorExceptionThrower.ArgumentException(arg, $"Argument '{arg.Name}' not must be match with pattern '{pattern}'. Current value: {ExceptionMessageHelper.GetStringValueForMessage(arg.Value)}"); } return(arg); }
/// <summary> /// Throws <see cref="ArgumentException"/> if argument is not <c>null</c> or length is more than 0 /// </summary> /// <exception cref="ArgumentException">Throws if argument is not <c>null</c> or length is more than 0</exception> public static Argument <string> NullOrEmpty(this Argument <string> arg) { if (arg.ValidationIsDisabled()) { return(arg); } if (!string.IsNullOrEmpty(arg.Value)) { ValidationErrorExceptionThrower.ArgumentException(arg, $"Argument '{arg.Name}' must be empty or null. Current value: {ExceptionMessageHelper.GetStringValueForMessage(arg.Value)}"); } return(arg); }