public static Param <IDictionary <TKey, TValue> > HasItems <TKey, TValue>(this Param <IDictionary <TKey, TValue> > param)
        {
            if (param.Value == null || param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <T> HasItems <T>(this Param <T> param) where T : class, ICollection
        {
            if (param.Value == null || param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
        public static Param <T[]> HasItems <T>(this Param <T[]> param)
        {
            if (param.Value == null || param.Value.Length < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsEmptyCollection);
            }

            return(param);
        }
Пример #4
0
        public static Param <DateTime> IsLt(this Param <DateTime> param, DateTime limit)
        {
            if (param.Value >= limit)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotLt.Inject(param.Value, limit));
            }

            return(param);
        }
Пример #5
0
        public static TypeParam IsOfType(this TypeParam param, Type type)
        {
            if (!param.Type.Equals(type))
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.EnsureExtensions_IsNotOfType.Inject(param.Type.FullName));
            }

            return(param);
        }
        public static Param <string> IsGuid(this Param <string> param)
        {
            Guid guid;

            if (!Guid.TryParse(param.Value, out guid))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotGuid.Inject(param.Value));
            }

            return(param);
        }
Пример #7
0
        public static void IsNot <T>(this Param <T> param, T expected, IComparer <T> comparer)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (param.Value.IsEq(expected, comparer))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Comp_IsNot_Failed.Inject(param.Value, expected));
            }
        }
Пример #8
0
        public static void IsNotOfType(this TypeParam param, Type type)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (param.Type == type)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Types_IsNotOfType_Failed.Inject(type.FullName));
            }
        }
Пример #9
0
        public static void IsNotEmpty(this Param <Guid> param)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (param.Value.Equals(Guid.Empty))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Guids_IsNotEmpty_Failed);
            }
        }
        public static void SizeIs(this Param <string> param, int expected)
        {
            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            if (param.Value.Length != expected)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Strings_SizeIs_Failed.Inject(expected, param.Value.Length));
            }
        }
        public static void IsNotNullOrEmpty(this Param <string> param)
        {
            if (param.Value == null)
            {
                throw ExceptionFactory.CreateForParamNullValidation(param, ExceptionMessages.Common_IsNotNull_Failed);
            }

            if (string.IsNullOrEmpty(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Strings_IsNotNullOrEmpty_Failed);
            }
        }
Пример #12
0
        public static void IsTrue(this Param <bool> param)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (!param.Value)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Booleans_IsTrueFailed);
            }
        }
Пример #13
0
        public static void IsNotDefault <T>(this Param <T> param) where T : struct
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (default(T).Equals(param.Value))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.ValueTypes_IsNotDefault_Failed);
            }
        }
Пример #14
0
        public static void Is <T>(this Param <T> param, T expected) where T : IComparable <T>
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (!param.Value.IsEq(expected))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Comp_Is_Failed.Inject(param.Value, expected));
            }
        }
Пример #15
0
        public static void IsClass(this TypeParam param)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            if (!param.Type.GetTypeInfo().IsClass)
            {
                throw ExceptionFactory.CreateForParamValidation(param,
                                                                ExceptionMessages.Types_IsClass_Failed.Inject(param.Type.FullName));
            }
        }
        public static Param <ICollection <T> > HasItems <T>(this Param <ICollection <T> > param)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value == null || param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_HasItemsFailed);
            }

            return(param);
        }
Пример #17
0
        public static Param <T[]> SizeIs <T>(this Param <T[]> param, int expected)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value.Length != expected)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_SizeIs_Wrong.Inject(expected, param.Value.Length));
            }

            return(param);
        }
        public static Param <IDictionary <TKey, TValue> > SizeIs <TKey, TValue>(this Param <IDictionary <TKey, TValue> > param, long expected)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value.Count != expected)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_SizeIs_Failed.Inject(expected, param.Value.Count));
            }

            return(param);
        }
        public static Param <T[]> Any <T>(this Param <T[]> param, Func <T, bool> predicate)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (!param.Value.Any(predicate))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_Any_Failed);
            }

            return(param);
        }
        public static void Any <TKey, TValue>(this Param <Dictionary <TKey, TValue> > param, Func <KeyValuePair <TKey, TValue>, bool> predicate)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            param.IsNotNull();

            if (!param.Value.Any(predicate))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_Any_Failed);
            }
        }
        public static void HasItems <T>(this Param <IList <T> > param)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            param.IsNotNull();

            if (param.Value.Count < 1)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_HasItemsFailed);
            }
        }
        public static void ContainsKey <TKey, TValue>(this Param <Dictionary <TKey, TValue> > param, TKey key)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            param.IsNotNull();

            if (!param.Value.ContainsKey(key))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_ContainsKey_Failed.Inject(key));
            }
        }
        public static void SizeIs <T>(this Param <IList <T> > param, long expected)
        {
            if (!Ensure.IsActive)
            {
                return;
            }

            param.IsNotNull();

            if (param.Value.Count != expected)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.Collections_SizeIs_Failed.Inject(expected, param.Value.Count));
            }
        }
Пример #24
0
        public static Param <Guid> IsNotEmpty(this Param <Guid> param)
        {
            if (!Ensure.IsActive)
            {
                return(param);
            }

            if (param.Value.Equals(Guid.Empty))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsEmptyGuid);
            }

            return(param);
        }
Пример #25
0
        public static Param <short> IsInRange(this Param <short> param, short min, short max)
        {
            if (param.Value < min)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLow.Inject(param.Value, min));
            }

            if (param.Value > max)
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToHigh.Inject(param.Value, max));
            }

            return(param);
        }
Пример #26
0
        public static Param <T> IsInRange <T>(this Param <T> param, T min, T max) where T : struct, IComparable <T>
        {
            if (param.Value.IsLt(min))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToLow.Inject(param.Value, min));
            }

            if (param.Value.IsGt(max))
            {
                throw ExceptionFactory.CreateForParamValidation(param, ExceptionMessages.EnsureExtensions_IsNotInRange_ToHigh.Inject(param.Value, max));
            }

            return(param);
        }