Class ResolvedValidationOptions
A model for options which affect how a validator should behave whilst it is performing its validation.
Inheritance
Inherited Members
Namespace: CSF.Validation
Assembly: CSF.Validation.Abstractions.dll
Syntax
public class ResolvedValidationOptions
Remarks
In this model, every property is non-nullable and has a concrete value. Do not use this class to specify options at the developer/API level. Instead use ValidationOptions for that purpose.
Properties
| Improve this Doc View SourceAccessorExceptionBehaviour
Gets or sets a value which indicates the default behaviour should a value-accessor raise an exception during validation.
Declaration
public ValueAccessExceptionBehaviour AccessorExceptionBehaviour { get; set; }
Property Value
Type | Description |
---|---|
ValueAccessExceptionBehaviour |
Remarks
The validator automatically catches exceptions when executing validation rules and converts each of these into a rule result which has an outcome of Errored. This option configures what the validator should do by default when accessing a value to be validated throws an exception.
Please note that the behaviour specified in this validation option can be overridden by individual values in the validation manifest. The property AccessorExceptionBehaviour, where set to a non-null value, will override the behaviour specified upon this options property.
The hard-coded default for this value (if not specified upon any ValidationOptions instance) is TreatAsError.
See Also
EnableMessageGeneration
Gets or sets a value which determines whether or not the validator should generate validation feedback messages, such as for rules which fail validation.
Declaration
public bool EnableMessageGeneration { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
An optional piece of functionality within this validation framework is the generation of human-readable feedback messages relating to validation, typically for failures or errors. By default this functionality is disabled and the logic to generate messages is skipped, providing a performance boost when it is not going to be used.
Setting this option value to true enables this functionality and means that every validation rule result has the opportunity to have a Message generated with feedback advising the user what to do about the validation failure. If thie functionality is not enabled then that message property will be left at its unset/default value of null.
For more information about validation feedback message generation, you are encouraged to read the corresponding documentation.
The hard-coded default for this value (if not specified upon any ValidationOptions instance) is false.
See Also
| Improve this Doc View SourceEnableRuleParallelization
Gets or sets a value indicating whether or not rules are permitted to be executed/evaluated in parallel. This will offer a modest performance improvement, particularly if your rules perform a lot of CPU-bound work.
Declaration
public bool EnableRuleParallelization { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Running rules in parallel requires both of the following:
- This configuration option must be set to true (this is the default setting).
- Individual rule classes must be decorated with the ParallelizableAttribute to be eligible for parallel execution.
For rules which are executed in parallel, the default .NET Task Parallel Library is used. More can be read about this at https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-based-asynchronous-programming
The hard-coded default for this value (if not specified upon any ValidationOptions instance) is false.
See Also
| Improve this Doc View SourceInstrumentRuleExecution
Gets or sets a value that indicates whether or not the validaiton rule process should record and add instrumentation data to the results.
Declaration
public bool InstrumentRuleExecution { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Developers wishing to benchmark or profile validation rules may find this useful. When this option is set to true, additional information is added to the validation results, including information about the length of time spent executing rules and/or generating validation feedback messages.
Because the act of gathering this information causes some performance degradation, this option defaults to false.
See Also
| Improve this Doc View SourceRuleThrowingBehaviour
Gets or sets the exception-throwing behaviour for validation rules.
Declaration
public RuleThrowingBehaviour RuleThrowingBehaviour { get; set; }
Property Value
Type | Description |
---|---|
RuleThrowingBehaviour |
Remarks
When a validator - an IValidator or an IValidator<TValidated> - completes validation it might throw an exception, governed by this option setting. If this is set to OnError then the validator will throw if any result indicates Errored. If this is set to OnFailure then the validator will throw if any result indicates either Failed or Errored.
The hard-coded default for this value (if not specified upon any ValidationOptions instance) is OnError.
See Also
| Improve this Doc View SourceTreatMessageGenerationErrorsAsRuleErrors
Gets or sets a value that determines whether or not the validator should treat errors encountered whilst generating validation failure messages as rule errors.
Declaration
public bool TreatMessageGenerationErrorsAsRuleErrors { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Firstly, this option is irrelevant if EnableMessageGeneration is not true.
When this option is not true, then any errors encountered by the validation framework whilst generating validation failure messages are ignored. In this case, if a message was to be generated for a rule result but an error meant that it could not be then the Message property of the validation rule result is left null but the validation will otherwise complete normally.
If this option is set to true then if an error occurs whilst generating a message for a validation rule then that rule will have its outcome set to Errored and the exception will be stored within the Exception property. This could then cause the overall validation process to raise an exception, depending upon the setting of the RuleThrowingBehaviour option.