Ejemplo n.º 1
0
        public static ArgumentEx <string> IsNotNullOrEmpty(this ArgumentEx <string> arg)
        {
            arg.IsNotNull();
            arg.IsNotEmpty();

            return(arg);
        }
Ejemplo n.º 2
0
        public static ArgumentEx <string> FileDoesExistAtPath(this ArgumentEx <string> arg)
        {
            if (!File.Exists(arg.Value))
            {
                throw new IOException("File does not exist at path: {0}".FormatWith(arg.Value));
            }

            return(arg);
        }
Ejemplo n.º 3
0
        public static ArgumentEx <string> StartsWith(this ArgumentEx <string> arg, string prefix)
        {
            if (!arg.Value.StartsWith(prefix))
            {
                throw new ArgumentException("Parameter {0} must start with {1}.".FormatWith(arg.Name, prefix), arg.Name);
            }

            return(arg);
        }
Ejemplo n.º 4
0
        public static ArgumentEx <byte> MeetsCriteria(this ArgumentEx <byte> x, Func <byte, bool> predicate)
        {
            if (predicate(x))
            {
                return(x);
            }

            throw new ArgumentException("The argument {0} does not meet the required criteria.", x.Name);
        }
Ejemplo n.º 5
0
        public static ArgumentEx <T> IsNotNull <T>(this ArgumentEx <T> arg) where T : class
        {
            if (arg.Value == null)
            {
                throw new ArgumentNullException(arg.Name);
            }

            return(arg); // for fluency
        }
Ejemplo n.º 6
0
        public static ArgumentEx <string> IsNotEmpty(this ArgumentEx <string> arg)
        {
            if (arg == "")
            {
                throw new ArgumentException("The argument {0} may not be empty.".FormatWith(arg.Name), arg.Name);
            }

            return(arg);
        }
Ejemplo n.º 7
0
        public static ArgumentEx <T> ExistsIn <T>(this ArgumentEx <T> arg, IEnumerable <T> list)
        {
            if (!list.Contains(arg.Value))
            {
                throw new ArgumentException(
                          "The argument {0} does not exist in the list provided.".FormatWith(arg.Name),
                          arg.Name);
            }

            return(arg);
        }
Ejemplo n.º 8
0
        public static ArgumentEx <byte> IsBetween(
            this ArgumentEx <byte> x,
            byte lowerBound,
            byte upperBound,
            bool inclusive = true)
        {
            if (!inclusive)
            {
                if (x > lowerBound && x < upperBound)
                {
                    return(x);
                }
            }

            if (x >= lowerBound && x <= upperBound)
            {
                return(x);
            }

            throw new ArgumentException(
                      "The argument {0} is not between {1} and {2}.".FormatWith(x.Name, lowerBound, upperBound));
        }