Class Validator<T>
A generic validator that supports fluent API for building validation rules.
Implements
IValidator<T>
Inherited Members
Namespace: ValidationFramework
Assembly: ValidationFramework.dll
Syntax
public class Validator<T> : IValidator<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of value to validate. |
Constructors
| Edit this page View SourceValidator(string?)
Initializes a new instance of the Validator<T> class.
Declaration
public Validator(string? fieldName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fieldName | Optional field name for error reporting. |
Methods
| Edit this page View SourceAddRule(Func<T, bool>, string)
Adds a validation rule to this validator.
Declaration
public Validator<T> AddRule(Func<T, bool> rule, string errorMessage)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<T, bool> | rule | The function that defines the validation condition. |
| string | errorMessage | The error message to return if validation fails. |
Returns
| Type | Description |
|---|---|
| Validator<T> | This validator instance for method chaining. |
Validate(T)
Validates the specified value against all rules in this validator.
Declaration
public ValidationResult Validate(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The value to validate. |
Returns
| Type | Description |
|---|---|
| ValidationResult | A ValidationResult containing all validation errors. |