コード例 #1
0
        public static Argument <T> IsNotNull <T>(this Argument <T> argument)
            where T : class
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            return(argument);
        }
コード例 #2
0
        public static Argument <T?> IsNotNull <T>(this Argument <T?> argument)
            where T : struct
        {
            if (argument.Value == null || !argument.Value.HasValue)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            return(argument);
        }
コード例 #3
0
        public static Argument <string> IsNotNullOrEmpty(this Argument <string> argument)
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (argument.Value.Length == 0)
            {
                throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.WasEmptyString);
            }

            return(argument);
        }
コード例 #4
0
        public static Argument <T> DoesNotContainNull <T>(this Argument <T> argument)
            where T : IEnumerable
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (argument.Value.Cast <object>().Any(o => o == null))
            {
                throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.ContainedNull);
            }

            return(argument);
        }
コード例 #5
0
        public static Argument <T> IsNotEmpty <T>(this Argument <T> argument)
            where T : IEnumerable
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (!argument.Value.GetEnumerator().MoveNext())
            {
                throw ExceptionFactory.CreateArgumentException(argument, ExceptionMessages.Current.EmptyCollection);
            }

            return(argument);
        }
コード例 #6
0
        private static Argument <T> IsGreaterThanOrEqualToImpl <T>(Argument <T> argument, object limit)
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (argument.CompareValueTo(limit) < 0)
            {
                throw ExceptionFactory.OutOfRange(
                          argument,
                          ExceptionMessages.Current.NotGreaterThanOrEqualTo.Inject(limit, argument.Value));
            }

            return(argument);
        }
コード例 #7
0
ファイル: TypeArgumentExtensions.cs プロジェクト: Miista/Krav
        public static Argument <Type> Is(this Argument <Type> argument, Type expectedType)
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (!expectedType.IsAssignableFrom(argument.Value))
            {
                throw ExceptionFactory.CreateArgumentException(
                          argument,
                          ExceptionMessages.Current.IsNotExpectedType.Inject(expectedType.FullName, argument.Value.FullName));
            }

            return(argument);
        }
コード例 #8
0
        public static Argument <T> IsInRange <T>(this Argument <T> argument, T min, T max)
            where T : IComparable <T>
        {
            if (argument.Value == null)
            {
                throw ExceptionFactory.CreateNullException(argument);
            }

            if (argument.CompareValueTo(min) < 0)
            {
                throw ExceptionFactory.OutOfRange(
                          argument,
                          ExceptionMessages.Current.NotInRange_TooLow.Inject(min, max));
            }

            if (argument.CompareValueTo(max) > 0)
            {
                throw ExceptionFactory.OutOfRange(
                          argument,
                          ExceptionMessages.Current.NotInRange_TooHigh.Inject(min, max));
            }

            return(argument);
        }