Class BaseValidator<T>
- Namespace
- Cratis.Arc.Validation
- Assembly
- Cratis.Arc.Core.dll
Represents a base validator that we use for discovery.
public class BaseValidator<T> : AbstractValidator<T>, IValidator<T>, IValidator, IEnumerable<IValidationRule>, IEnumerable, IHasIgnoredConceptRuleMembers
Type Parameters
TType of object the validator is for.
- Inheritance
-
AbstractValidator<T>BaseValidator<T>
- Implements
-
IValidator<T>IValidatorIEnumerable<IValidationRule>
- Derived
- Inherited Members
-
AbstractValidator<T>.Validate(T)AbstractValidator<T>.Validate(ValidationContext<T>)AbstractValidator<T>.CreateDescriptor()AbstractValidator<T>.WhenAsync(Func<T, ValidationContext<T>, CancellationToken, Task<bool>>, Action)AbstractValidator<T>.Include(IValidator<T>)AbstractValidator<T>.GetEnumerator()AbstractValidator<T>.PreValidate(ValidationContext<T>, ValidationResult)AbstractValidator<T>.RaiseValidationException(ValidationContext<T>, ValidationResult)AbstractValidator<T>.OnRuleAdded(IValidationRule<T>)AbstractValidator<T>.ClassLevelCascadeModeAbstractValidator<T>.RuleLevelCascadeMode
- Extension Methods
Constructors
BaseValidator()
public BaseValidator()
Properties
IgnoredConceptRuleMembers
Gets the camelCased top-level property names for which a registered ConceptValidator<T> (or any other IDiscoverableValidator<T> for the concept type) should not be invoked while validating this model.
public IReadOnlySet<string> IgnoredConceptRuleMembers { get; }
Property Value
Methods
RuleFor<TValue>(Expression<Func<T, ConceptAs<TValue>>>)
Defines a validation rule for a property that is a ConceptAs<T>, unwrapping the
inner value so that standard FluentValidation rules (e.g. NotEmpty) operate on the primitive.
public IConceptRuleBuilder<T, TValue> RuleFor<TValue>(Expression<Func<T, ConceptAs<TValue>>> expression) where TValue : IComparable
Parameters
expressionExpression<Func<T, ConceptAs<TValue>>>The expression representing the property to validate.
Returns
- IConceptRuleBuilder<T, TValue>
An IConceptRuleBuilder<T, TValue> instance on which validators can be defined.
Type Parameters
TValueThe primitive type wrapped by the concept.
Remarks
A single generic overload is used intentionally. C# type inference resolves TValue
exclusively from the class hierarchy (MyConcept : ConceptAs<Guid> → TValue = Guid)
without considering user-defined implicit conversions. This eliminates the CS0121 ambiguity that
arises when a concept type has implicit operators to multiple ConceptAs<string> subtypes
(e.g. EventSourceId and ReadModelKey).
WhenCommand(Action)
Define a condition for when the context is a command.
public IConditionBuilder WhenCommand(Action callback)
Parameters
callbackActionCallback for defining the rules when it is a command.
Returns
- IConditionBuilder
FluentValidation.IConditionBuilder for building on the condition.
WhenQuery(Action)
Define a condition for when the context is a command.
public IConditionBuilder WhenQuery(Action callback)
Parameters
callbackActionCallback for defining the rules when it is a command.
Returns
- IConditionBuilder
FluentValidation.IConditionBuilder for building on the condition.