Exemplo n.º 1
0
        public static ValidationResult <TArgument> IsNull <TArgument>(this ValidationTarget <TArgument> target, String targetParameterName)
            where TArgument : class
        {
            if (target.Argument is null)
            {
                throw new ArgumentNullException(targetParameterName);
            }

            return(target.Result);
        }
        public static ValidationResult <Type> IsNotSupportedType(this ValidationTarget <Type> target, IEnumerable <Type> supportedTypes, String targetParameterName)
        {
            supportedTypes.RejectIf().IsNullOrEmpty(nameof(supportedTypes));

            if (supportedTypes.Contains(target.Argument))
            {
                return(target.Result);
            }

            throw new UnsupportedTypeArgumentException(target.Argument, targetParameterName);
        }
        public static ValidationResult <Type> IsNotSupportedType(this ValidationTarget <Type> target, Type supportedBaseType, String targetParameterName)
        {
            supportedBaseType.RejectIf().IsNull(nameof(supportedBaseType));

            if (supportedBaseType.GetTypeInfo().IsAssignableFrom(target.Argument))
            {
                return(target.Result);
            }

            throw new UnsupportedTypeArgumentException(target.Argument, targetParameterName);
        }
        public static ValidationResult <String> IsNullOrEmpty(this ValidationTarget <String> target, String targetParameterName)
        {
            if (target.Argument is null)
            {
                throw new ArgumentNullException(targetParameterName);
            }
            else if (target.Argument.Length == 0)
            {
                throw new ArgumentEmptyException(targetParameterName);
            }

            return(target.Result);
        }
        public static ValidationResult <String> LengthIsGreaterThan(this ValidationTarget <String> target, Int32 exclusiveUpperBoundary, String targetParameterName)
        {
            if (target.Argument.Length.CompareTo(exclusiveUpperBoundary) == 1)
            {
                if (targetParameterName is null)
                {
                    throw new ArgumentOutOfRangeException(null, $"The argument cannot have character length greater than {exclusiveUpperBoundary}.");
                }

                throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot have character length greater than {exclusiveUpperBoundary}.");
            }

            return(target.Result);
        }
        public static ValidationResult <String> LengthIsLessThanOrEqualTo(this ValidationTarget <String> target, Int32 inclusiveLowerBoundary, String targetParameterName)
        {
            if (target.Argument?.Length.CompareTo(inclusiveLowerBoundary) != 1)
            {
                if (targetParameterName is null)
                {
                    throw new ArgumentOutOfRangeException(null, $"The argument cannot have character length less than or equal to {inclusiveLowerBoundary}.");
                }

                throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot have character length less than or equal to {inclusiveLowerBoundary}.");
            }

            return(target.Result);
        }
        public static ValidationResult <String> DoesNotMatchRegularExpression(this ValidationTarget <String> target, String regularExpressionPattern, String targetParameterName)
        {
            try
            {
                if (target.Argument.MatchesRegularExpression(regularExpressionPattern))
                {
                    return(target.Result);
                }
            }
            catch (ArgumentException exception)
            {
                throw new StringArgumentPatternException(regularExpressionPattern, targetParameterName, null, exception);
            }
            catch (RegexMatchTimeoutException exception)
            {
                throw new StringArgumentPatternException(regularExpressionPattern, targetParameterName, null, exception);
            }

            throw new StringArgumentPatternException(regularExpressionPattern, targetParameterName);
        }
        public static ValidationResult <TArgument> IsEqualTo <TArgument>(this ValidationTarget <TArgument> target, TArgument otherArgument, String targetParameterName, String otherParameterName)
            where TArgument : class, IEquatable <TArgument>
        {
            if (target.Argument.Equals(otherArgument))
            {
                if (targetParameterName is null)
                {
                    if (otherParameterName is null)
                    {
                        throw new ArgumentOutOfRangeException(null, $"The argument cannot be equal to {otherArgument}.");
                    }

                    throw new ArgumentOutOfRangeException(null, $"The argument cannot be equal to the argument for {otherParameterName}.");
                }
                else if (otherParameterName is null)
                {
                    throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot be equal to {otherArgument}.");
                }

                throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot be equal to the argument for {otherParameterName}.");
            }

            return(target.Result);
        }
Exemplo n.º 9
0
        public static ValidationResult <TArgument> IsGreaterThan <TArgument>(this ValidationTarget <TArgument> target, TArgument otherArgument, String targetParameterName, String otherParameterName)
            where TArgument : IComparable <TArgument>
        {
            if (target.Argument.CompareTo(otherArgument) == 1)
            {
                if (targetParameterName is null)
                {
                    if (otherParameterName is null)
                    {
                        throw new ArgumentOutOfRangeException(null, $"The argument cannot be greater than {otherArgument}.");
                    }

                    throw new ArgumentOutOfRangeException(null, $"The argument cannot be greater than the argument for {otherParameterName}.");
                }
                else if (otherParameterName is null)
                {
                    throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot be greater than {otherArgument}.");
                }

                throw new ArgumentOutOfRangeException(targetParameterName, $"The argument for {targetParameterName} cannot be greater than the argument for {otherParameterName}.");
            }

            return(target.Result);
        }
 public static ValidationResult <TArgument> IsEqualTo <TArgument>(this ValidationTarget <TArgument> target, TArgument otherObject)
     where TArgument : class, IEquatable <TArgument> => target.IsEqualTo(otherObject, null);
Exemplo n.º 11
0
 public static ValidationResult <TArgument> IsGreaterThan <TArgument>(this ValidationTarget <TArgument> target, TArgument exclusiveUpperBoundary, String targetParameterName)
     where TArgument : IComparable <TArgument> => target.IsGreaterThan(exclusiveUpperBoundary, targetParameterName, null);
Exemplo n.º 12
0
 public static ValidationResult <TArgument> IsLessThan <TArgument>(this ValidationTarget <TArgument> target, TArgument exclusiveLowerBoundary)
     where TArgument : IComparable <TArgument> => target.IsLessThan(exclusiveLowerBoundary, null);
Exemplo n.º 13
0
 public static ValidationResult <TArgument> IsLessThanOrEqualTo <TArgument>(this ValidationTarget <TArgument> target, TArgument inclusiveLowerBoundary, String targetParameterName)
     where TArgument : IComparable <TArgument> => target.IsLessThanOrEqualTo(inclusiveLowerBoundary, targetParameterName, null);
 public static ValidationResult <String> IsNullOrEmpty(this ValidationTarget <String> target) => target.IsNullOrEmpty(null);
Exemplo n.º 15
0
 public static ValidationResult <TArgument> IsGreaterThanOrEqualTo <TArgument>(this ValidationTarget <TArgument> target, TArgument inclusiveUpperBoundary)
     where TArgument : IComparable <TArgument> => target.IsGreaterThanOrEqualTo(inclusiveUpperBoundary, null);
Exemplo n.º 16
0
        internal static ValidationResult <TArgument> RejectIfIsNullOrEmpty <TArgument, T>(this ValidationTarget <TArgument> target, String targetParameterName)
            where TArgument : IEnumerable <T>
        {
            if (target.Argument == null)
            {
                throw new ArgumentNullException(targetParameterName);
            }
            else if (target.Argument.Any() == false)
            {
                throw new ArgumentEmptyException(targetParameterName);
            }

            return(target.Result);
        }
 public static ValidationResult <IReadOnlyDictionary <TKey, TValue> > IsNullOrEmpty <TKey, TValue>(this ValidationTarget <IReadOnlyDictionary <TKey, TValue> > target) => target.IsNullOrEmpty(null);
 public static ValidationResult <String> LengthIsGreaterThan(this ValidationTarget <String> target, Int32 exclusiveUpperBoundary) => target.LengthIsGreaterThan(exclusiveUpperBoundary, null);
 public static ValidationResult <Type> IsNotSupportedType(this ValidationTarget <Type> target, IEnumerable <Type> supportedTypes) => target.IsNotSupportedType(supportedTypes, null);
Exemplo n.º 20
0
 internal ValidationResult(ValidationTarget <TArgument> target)
 {
     Target = target;
 }
 public static ValidationResult <String> LengthIsLessThanOrEqualTo(this ValidationTarget <String> target, Int32 inclusiveLowerBoundary) => target.LengthIsLessThanOrEqualTo(inclusiveLowerBoundary, null);
Exemplo n.º 22
0
 public static ValidationResult <TArgument> IsNull <TArgument>(this ValidationTarget <TArgument> target)
     where TArgument : class => target.IsNull(null);
 public static ValidationResult <TArgument> IsEqualTo <TArgument>(this ValidationTarget <TArgument> target, TArgument otherObject, String targetParameterName)
     where TArgument : class, IEquatable <TArgument> => target.IsEqualTo(otherObject, targetParameterName, null);
 public static ValidationResult <IReadOnlyDictionary <TKey, TValue> > IsNullOrEmpty <TKey, TValue>(this ValidationTarget <IReadOnlyDictionary <TKey, TValue> > target, String targetParameterName) => target.RejectIfIsNullOrEmpty <IReadOnlyDictionary <TKey, TValue>, KeyValuePair <TKey, TValue> >(targetParameterName);
 public static ValidationResult <Stack <T> > IsNullOrEmpty <T>(this ValidationTarget <Stack <T> > target) => target.IsNullOrEmpty(null);
 public static ValidationResult <String> DoesNotMatchRegularExpression(this ValidationTarget <String> target, String regularExpressionPattern) => target.DoesNotMatchRegularExpression(regularExpressionPattern, null);
 public static ValidationResult <Type> IsNotSupportedType(this ValidationTarget <Type> target, Type supportedBaseType) => target.IsNotSupportedType(supportedBaseType, null);
 public static ValidationResult <IReadOnlyList <T> > IsNullOrEmpty <T>(this ValidationTarget <IReadOnlyList <T> > target) => target.IsNullOrEmpty(null);
 public static ValidationResult <IReadOnlyList <T> > IsNullOrEmpty <T>(this ValidationTarget <IReadOnlyList <T> > target, String targetParameterName) => target.RejectIfIsNullOrEmpty <IReadOnlyList <T>, T>(targetParameterName);
Exemplo n.º 30
0
 public static ValidationResult <IEnumerable <T> > IsNullOrEmpty <T>(this ValidationTarget <IEnumerable <T> > target, String targetParameterName) => target.RejectIfIsNullOrEmpty <IEnumerable <T>, T>(targetParameterName);