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))); }
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))); }
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))); }
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))); }
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))); }
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))); }