Table of Contents

Class AbstractBatchValidator<T>

Namespace
Visus.AddressValidation.Validation
Assembly
Visus.AddressValidation.dll

Base class for implementing a batch validator that produces one independent IValidationResult per item in a batch response.

public abstract class AbstractBatchValidator<T> : IBatchValidator<T> where T : class

Type Parameters

T

The object instance to be validated.

Inheritance
AbstractBatchValidator<T>
Implements
Inherited Members

Methods

ExecuteAsync(T, IReadOnlyList<int>, CancellationToken)

Executes validation against the specified instance, producing one result per expected item.

public ValueTask<IReadOnlyList<IValidationResult>> ExecuteAsync(T instance, IReadOnlyList<int> requestIndexes, CancellationToken cancellationToken = default)

Parameters

instance T

The instance which will be validated against.

requestIndexes IReadOnlyList<int>

The original, caller-facing index of each request actually sent to the API, in the same order the requests were sent. Its count is the number of items expected in the result; implementations should use the values themselves (rather than the positional loop index) when a validation message needs to reference an item's position, since requests that failed local validation may have been filtered out before the API call.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the work.

Returns

ValueTask<IReadOnlyList<IValidationResult>>

A list of exactly requestIndexes.Count IValidationResult objects, positionally aligned with the items sent to the API.

PreValidateAsync(T, IReadOnlyList<int>, IReadOnlyList<ISet<ValidationState>>, CancellationToken)

Determines if validation should continue, providing a means to add shared (batch-wide) validation state that applies to every item prior to per-item validation.

protected virtual ValueTask<bool> PreValidateAsync(T instance, IReadOnlyList<int> requestIndexes, IReadOnlyList<ISet<ValidationState>> results, CancellationToken cancellationToken = default)

Parameters

instance T

The instance to perform validation against.

requestIndexes IReadOnlyList<int>

The original, caller-facing index of each request expected in the result.

results IReadOnlyList<ISet<ValidationState>>

One ISet<T> of ValidationState objects per expected item, indexed positionally.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the work.

Returns

ValueTask<bool>

true to continue with per-item validation; otherwise, false.

ValidateAsync(T, IReadOnlyList<int>, IReadOnlyList<ISet<ValidationState>>, CancellationToken)

Validates the specified instance, populating per-item validation state.

protected virtual ValueTask ValidateAsync(T instance, IReadOnlyList<int> requestIndexes, IReadOnlyList<ISet<ValidationState>> results, CancellationToken cancellationToken = default)

Parameters

instance T

The object to perform validation against.

requestIndexes IReadOnlyList<int>

The original, caller-facing index of each request expected in the result.

results IReadOnlyList<ISet<ValidationState>>

One ISet<T> of ValidationState objects per expected item, indexed positionally.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the work.

Returns

ValueTask

A task that represents the asynchronous validation operation.