Raise a validation failure¶
Build and throw a validation exception carrying structured failure detail, triggered when caller detects invalid input or state and needs to surface property-level errors.
| Field | Value |
|---|---|
| Operation ID | OP-019 |
| Trigger | Caller detects invalid input or state and needs to surface property-level errors |
| Inputs | none / IValidationResult / errorMessage / propertyName + errorMessage |
| Outputs | A throwable exception carrying an IValidationResult |
| Primary components | SaifValidationException` constructors; `ValidationResult`; `ValidationFailure |
| Entry point | Common/SAIF.Common/Classes/SaifValidationException.cs |
Steps¶
- Parameterless ctor: attach a fresh empty
ValidationResultso theValidationResultproperty is never null. (BR-044) (IValidationResult result)ctor: attach the caller's result as-is. (BR-044)(string errorMessage)ctor: build aValidationResultholding oneValidationFailurewith an empty property name. (BR-045)(string propertyName, string errorMessage)ctor: build aValidationResultholding oneValidationFailurebound to that property. (BR-045)ValidationResult()initialisesErrorsandMessagesto empty lists;ValidationResult(IEnumerable<ValidationFailure>)initialises both and then replacesErrorswith the supplied failures only when the argument is non-null. (BR-046)ValidationResult.IsValidis computed as!Errors.Any()— validity is always derived, never assigned. (BR-047)
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["Caller constructs a<br>SaifValidationException"]) --> S1["Parameterless ctor: attach<br>fresh empty ValidationResult"]
S1 --> S2["(IValidationResult) ctor:<br>attach caller's result as-is"]
S2 --> S3["(errorMessage) ctor: build failure<br>with empty property name"]
S3 --> S4["(propertyName, errorMessage) ctor:<br>build failure bound to property"]
S4 --> S5["ValidationResult ctors init<br>Errors and Messages collections"]
S5 --> S6["IsValid computed as<br>!Errors.Any()"]
S6 --> End(["Exception ready to throw"])
Related documentation¶
Sources¶
Common/SAIF.Common/Classes/SaifValidationException.csCommon/SAIF.Common/Classes/ValidationResult.csCommon/SAIF.Common/Classes/ValidationFailure.cs