Example #1
0
        public static IRuleOut <TCollection> MinCollectionSize <TCollection, TItem>(this IRuleIn <TCollection> @this, int min)
            where TCollection : IEnumerable <TItem>
        {
            ThrowHelper.BelowZero(min, nameof(min));

            return(@this.RuleTemplate(m => m.Count() >= min, MessageKey.Collections.MinCollectionSize, Arg.Number(nameof(min), min)));
        }
Example #2
0
        public static IRuleOut <TCollection> ExactCollectionSize <TCollection, TItem>(this IRuleIn <TCollection> @this, int size)
            where TCollection : IEnumerable <TItem>
        {
            ThrowHelper.BelowZero(size, nameof(size));

            return(@this.RuleTemplate(m => m.Count() == size, MessageKey.Collections.ExactCollectionSize, Arg.Number(nameof(size), size)));
        }
Example #3
0
        public static IRuleOut <string> LengthBetween(this IRuleIn <string> @this, int min, int max)
        {
            ThrowHelper.BelowZero(min, nameof(min));
            ThrowHelper.BelowZero(max, nameof(max));
            ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max));

            return(@this.RuleTemplate(
                       v =>
            {
                var squashedLength = v.Replace(Environment.NewLine, " ").Length;

                return squashedLength >= min && squashedLength <= max;
            },
                       MessageKey.Texts.LengthBetween,
                       Arg.Number(nameof(min), min),
                       Arg.Number(nameof(max), max)));
        }
Example #4
0
        public static IRuleOut <TCollection> CollectionSizeBetween <TCollection, TItem>(this IRuleIn <TCollection> @this, int min, int max)
            where TCollection : IEnumerable <TItem>
        {
            ThrowHelper.BelowZero(min, nameof(min));
            ThrowHelper.BelowZero(max, nameof(max));

            ThrowHelper.InvalidRange(min, nameof(min), max, nameof(max));

            return(@this.RuleTemplate(
                       m =>
            {
                var count = m.Count();

                return count >= min && count <= max;
            },
                       MessageKey.Collections.CollectionSizeBetween,
                       Arg.Number(nameof(min), min),
                       Arg.Number(nameof(max), max)));
        }
Example #5
0
        public static IRuleOut <string> MinLength(this IRuleIn <string> @this, int min)
        {
            ThrowHelper.BelowZero(min, nameof(min));

            return(@this.RuleTemplate(v => v.Replace(Environment.NewLine, " ").Length >= min, MessageKey.Texts.MinLength, Arg.Number(nameof(min), min)));
        }
Example #6
0
        public static IRuleOut <string> ExactLength(this IRuleIn <string> @this, int length)
        {
            ThrowHelper.BelowZero(length, nameof(length));

            return(@this.RuleTemplate(v => v.Replace(Environment.NewLine, " ").Length == length, MessageKey.Texts.ExactLength, Arg.Number(nameof(length), length)));
        }