Skip to content

ObjectValidationBuilder`1

Namespace: MJCZone.DapperMatic.AspNetCore.Validation

Assembly: MJCZone.DapperMatic.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.

csharp
ObjectValidationBuilder`1(`0 item)

Parameters

  • item (`0) - The item to validate.

Methods

MethodSummary
NotNullValidates that a property is not null.
NotNullOrWhiteSpaceValidates that a string property is not null, empty, or whitespace.
NotNullOrEmptyValidates that a string property is not null or empty.
EqualValidates that a string property equals a specified value.
NotEqualValidates that a string property does not equal a specified value.
MinLengthValidates that a string property meets a specified minimum length.
MaxLengthValidates that a string property does not exceed a specified maximum length.
CustomAdds a custom validation rule.
BuildBuilds the validation result.
AssertAsserts that the item is valid, throwing an exception if not.
GetType
ToString
Equals
GetHashCode

NotNull

Validates that a property is not null.

csharp
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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ObjectValidationBuilder&lt;T&gt; 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.

csharp
ValidationResult Build()

Returns

Type: ValidationResult

The validation result.

Assert

Asserts that the item is valid, throwing an exception if not.

csharp
void Assert(ValidationExceptionType exceptionType)

Parameters

GetType

csharp
GetType()

ToString

csharp
ToString()

Equals

csharp
Equals()

GetHashCode

csharp
GetHashCode()