ObjectValidationBuilder`1
Namespace: MJCZone.MediaMatic.AspNetCore.Validation
Assembly: MJCZone.MediaMatic.AspNetCore
Summary
A builder for validating objects of type T.
public
Contents
Constructors (1) | Methods (14)
Constructors
ObjectValidationBuilder`1
Initializes a new instance of the ObjectValidationBuilder class.
ObjectValidationBuilder`1(`0 item)Parameters
- item (`0) - The item to validate.
Methods
| Method | Summary |
|---|---|
| NotNull | Validates that a property is not null. |
| NotNullOrWhiteSpace | Validates that a string property is not null, empty, or whitespace. |
| NotNullOrEmpty | Validates that a string property is not null or empty. |
| Equal | Validates that a string property equals a specified value. |
| NotEqual | Validates that a string property does not equal a specified value. |
| MinLength | Validates that a string property meets a specified minimum length. |
| MaxLength | Validates that a string property does not exceed a specified maximum length. |
| Custom | Adds a custom validation rule. |
| Build | Builds the validation result. |
| Assert | Asserts that the item is valid, throwing an exception if not. |
| GetType | |
| ToString | |
| Equals | |
| GetHashCode |
NotNull
Validates that a property is not null.
ObjectValidationBuilder<T> NotNull(Func{`0 selector, ``0} propertyName)Parameters
- selector (Func{`0) - A function to select the property from the item.
- propertyName (``0}) - The name of the property being validated (for error messages).
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
NotNullOrWhiteSpace
Validates that a string property is not null, empty, or whitespace.
ObjectValidationBuilder<T> NotNullOrWhiteSpace(
Func{`0 selector,
String} propertyName)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- propertyName (String}) - The name of the property being validated (for error messages).
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
NotNullOrEmpty
Validates that a string property is not null or empty.
ObjectValidationBuilder<T> NotNullOrEmpty(
Func{`0 selector,
String} propertyName)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- propertyName (String}) - The name of the property being validated (for error messages).
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
Equal
Validates that a string property equals a specified value.
ObjectValidationBuilder<T> Equal(
Func{`0 selector,
String} compareValue,
string ignoreCase,
bool errorMessage)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- compareValue (String}) - The value to compare against.
- ignoreCase (string) - Whether to ignore case when comparing strings.
- errorMessage (bool) - The error message to add if the validation fails.
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
NotEqual
Validates that a string property does not equal a specified value.
ObjectValidationBuilder<T> NotEqual(
Func{`0 selector,
String} compareValue,
string ignoreCase,
bool errorMessage)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- compareValue (String}) - The value to compare against.
- ignoreCase (string) - Whether to ignore case when comparing strings.
- errorMessage (bool) - The error message to add if the validation fails.
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
MinLength
Validates that a string property meets a specified minimum length.
ObjectValidationBuilder<T> MinLength(
Func{`0 selector,
String} minLength,
int propertyName,
string inclusive)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- minLength (String}) - The minimum allowed length.
- propertyName (int) - The name of the property being validated (for error messages).
- inclusive (string) - Whether the minimum length is inclusive.
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
MaxLength
Validates that a string property does not exceed a specified maximum length.
ObjectValidationBuilder<T> MaxLength(
Func{`0 selector,
String} maxLength,
int propertyName,
string inclusive)Parameters
- selector (Func{`0) - A function to select the string property from the item.
- maxLength (String}) - The maximum allowed length.
- propertyName (int) - The name of the property being validated (for error messages).
- inclusive (string) - Whether the maximum length is inclusive.
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
Custom
Adds a custom validation rule.
ObjectValidationBuilder<T> Custom(
Func{`0 condition,
Boolean} propertyName,
string errorMessage)Parameters
- condition (Func{`0) - A function that returns true if the item is valid, false otherwise.
- propertyName (Boolean}) - The name of the property being validated (for error messages).
- errorMessage (string) - The error message to add if the validation fails.
Returns
Type: ObjectValidationBuilder<T>
The current instance for method chaining.
Build
Builds the validation result.
ValidationResult Build()Returns
Type: ValidationResult
The validation result.
Assert
Asserts that the item is valid, throwing an exception if not.
void Assert(ValidationExceptionType exceptionType)Parameters
- exceptionType (ValidationExceptionType) - The type of exception to throw if validation fails.
GetType
GetType()ToString
ToString()Equals
Equals()GetHashCode
GetHashCode()