Native Validation DSL
v1.27.0 — ValidatorRuleBuilderExtensions adds 19 named, fluent methods on ValidatorRuleBuilder<T>. Property names are inferred automatically from Expression<Func<T, TProperty>> for clear default error messages — no raw predicates needed:
// Before — verbose, raw predicates, manual error messages
var validator = new ValidatorRuleBuilder<CreateUserRequest>()
.Rule(u => u.Name, "NotEmpty", "Name is required", v => !string.IsNullOrEmpty(v))
.Rule(u => u.Name, "MaxLength", "Name is too long", v => v.Length <= 100)
.Rule(u => u.Email, "Email", "Invalid email", v => emailRegex.IsMatch(v))
.Rule(u => u.Age, "Range", "Age must be 18–120", v => v >= 18 && v <= 120)
.Build();
// After — native DSL, field names auto-inferred in default messages
var validator = new ValidatorRuleBuilder<CreateUserRequest>()
.NotEmpty(u => u.Name) // "'Name' must not be empty."
.MaxLength(u => u.Name, 100) // "'Name' must not exceed 100 characters."
.EmailAddress(u => u.Email) // "'Email' must be a valid email address."
.Range(u => u.Age, 18, 120) // "'Age' must be between 18 and 120."
.Build();
| Category | Rules |
|---|---|
| String | NotEmpty, NotWhiteSpace, MinLength, MaxLength, Length, EmailAddress, Matches, StartsWith, EndsWith, Contains |
Numeric (IComparable<TNum>) |
GreaterThan, LessThan, Range, Positive, NonNegative |
| Collection | NotEmpty<TItem>, MinCount, MaxCount |
| Reference | NotNull |
All numeric rules are generic — work with int, long, double, decimal, and any IComparable<TNum>.