Class ValueAccessorBuilder<TValidated, TValue>
A builder which is used to configure how a member or other value of an object should be validated.
Inheritance
Inherited Members
Namespace: CSF.Validation.ValidatorBuilding
Assembly: CSF.Validation.dll
Syntax
public class ValueAccessorBuilder<TValidated, TValue> : IConfiguresValueAccessor<TValidated, TValue>, IHasValidationBuilderContext
Type Parameters
Name | Description |
---|---|
TValidated | The type of the overall object being validated. |
TValue | The type of this specific value being validated. |
Constructors
| Improve this Doc View SourceValueAccessorBuilder(ValidatorBuilderContext, IGetsRuleBuilder, IGetsValidatorBuilderContextFromBuilder, IGetsValidatorBuilderContext)
Initializes a new instance of ValueAccessorBuilder<TValidated, TValue>.
Declaration
public ValueAccessorBuilder(ValidatorBuilderContext context, IGetsRuleBuilder ruleBuilderFactory, IGetsValidatorBuilderContextFromBuilder validatorManifestFactory, IGetsValidatorBuilderContext builderContextFactory)
Parameters
Type | Name | Description |
---|---|---|
ValidatorBuilderContext | context | The context which should be used for newly-added rule-builders. |
IGetsRuleBuilder | ruleBuilderFactory | A factory for rule-builder instances. |
IGetsValidatorBuilderContextFromBuilder | validatorManifestFactory | A factory for validator manifest instances. |
IGetsValidatorBuilderContext | builderContextFactory | A factory for validator builder contexts. |
Properties
| Improve this Doc View SourceContext
Gets the validator builder context associated with the current instance.
Declaration
public ValidatorBuilderContext Context { get; }
Property Value
Type | Description |
---|---|
ValidatorBuilderContext |
Methods
| Improve this Doc View SourceAccessorExceptionBehaviour(Nullable<ValueAccessExceptionBehaviour>)
Configures the validator with a behaviour to use should the value-accessor for the current value raise an exception..
Declaration
public IConfiguresValueAccessor<TValidated, TValue> AccessorExceptionBehaviour(ValueAccessExceptionBehaviour? behaviour)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<ValueAccessExceptionBehaviour> | behaviour |
Returns
Type | Description |
---|---|
IConfiguresValueAccessor<TValidated, TValue> | A reference to the same builder object, enabling chaining of calls if desired. |
Remarks
This option will override the behaviour specified at AccessorExceptionBehaviour for the current value, if the specified behaviour is any non-null value. If this method is unused then it will be treated as if the specified ValueAccessExceptionBehaviour specified at this point were null and the AccessorExceptionBehaviour will be used instead.
See Also
| Improve this Doc View SourceAddRule<TRule>(Action<IConfiguresRule<TRule>>)
Adds a validation rule to validate the value indicated by the value accessor.
The rule type must be a class that implements IRule<TValidated> for the same
(or compatible contravariant) generic type TValue
.
Declaration
public IConfiguresValueAccessor<TValidated, TValue> AddRule<TRule>(Action<IConfiguresRule<TRule>> ruleDefinition = null)
where TRule : IRule<TValue>
Parameters
Type | Name | Description |
---|---|---|
System.Action<IConfiguresRule<TRule>> | ruleDefinition | An optional action which defines & configures the validation rule. |
Returns
Type | Description |
---|---|
IConfiguresValueAccessor<TValidated, TValue> | A reference to the same builder object, enabling chaining of calls if desired. |
Type Parameters
Name | Description |
---|---|
TRule | The concrete type of the validation rule. |
AddRules<TBuilder>()
Adds/imports rules from an object that implements IBuildsValidator<TValidated> for the generic
type TValue
.
Declaration
public IConfiguresValueAccessor<TValidated, TValue> AddRules<TBuilder>()
where TBuilder : IBuildsValidator<TValue>
Returns
Type | Description |
---|---|
IConfiguresValueAccessor<TValidated, TValue> | A reference to the same builder object, enabling chaining of calls if desired. |
Type Parameters
Name | Description |
---|---|
TBuilder | The type of a class implementing IBuildsValidator<TValidated>, specifying how a validator should be built. |
Remarks
This allows composition of validators, reuse of validation rules across differing validation scenarios and
additionally the building of validators which operate across complex object graphs.
All of the rules specified in the selected builder-type will be imported and added to the current validator,
validating the type TValue
.
AddRuleWithParent<TRule>(Action<IConfiguresRule<TRule>>)
Adds a "value validation rule" to validate the value & the validated object instance.
The rule type must be a class that implements IRule<TValue, TParent> for the same
(or compatible contravariant) generic types TValue
& TValidated
.
Declaration
public IConfiguresValueAccessor<TValidated, TValue> AddRuleWithParent<TRule>(Action<IConfiguresRule<TRule>> ruleDefinition = null)
where TRule : IRule<TValue, TValidated>
Parameters
Type | Name | Description |
---|---|---|
System.Action<IConfiguresRule<TRule>> | ruleDefinition | An optional action which defines & configures the validation rule. |
Returns
Type | Description |
---|---|
IConfiguresValueAccessor<TValidated, TValue> | A reference to the same builder object, enabling chaining of calls if desired. |
Type Parameters
Name | Description |
---|---|
TRule | The concrete type of the validation rule. |
WhenValueIs<TDerived>(Action<IConfiguresValueAccessor<TValidated, TDerived>>)
Adds validation configuration for polymorphic validatation when the runtime type
of the validated value is TDerived
.
Declaration
public IConfiguresValueAccessor<TValidated, TValue> WhenValueIs<TDerived>(Action<IConfiguresValueAccessor<TValidated, TDerived>> derivedConfig)
where TDerived : TValue
Parameters
Type | Name | Description |
---|---|---|
System.Action<IConfiguresValueAccessor<TValidated, TDerived>> | derivedConfig | Configuration which indicates what validation will be performed upon the value if its runtime type is |
Returns
Type | Description |
---|---|
IConfiguresValueAccessor<TValidated, TValue> | A reference to the same builder object, enabling chaining of calls if desired. |
Type Parameters
Name | Description |
---|---|
TDerived | The derived (child) type to be configured for validation in this polymorphic validation configuration. |
Remarks
Where the current validator configuration works to validate an object of type TValue
,
the value being validated might be a derived type of TValue
at runtime.
Polymorphic validation allows a developer to specify how a derived type should be validated, if that is the runtime
type of the value to be validated.
This method may be used multiple times, each time for a different type that is derived from TValue
.