Assemble a validation result and exception¶
Collect one or more validation failures into a ValidationResult and optionally wrap it in a throwable SaifValidationException. This operation is triggered when a consumer populates a ValidationResult after running validation logic, or constructs a SaifValidationException to report a single failure.
| Field | Value |
|---|---|
| Operation ID | OP-08 |
| Trigger | A consumer populates a ValidationResult after running validation logic, or constructs a SaifValidationException to report a single failure. |
| Inputs | PropertyName, ErrorMessage, AttemptedValue (for ValidationFailure); or propertyName/errorMessage (for SaifValidationException) |
| Outputs | A ValidationResult with populated Errors/Messages, or a SaifValidationException carrying a ValidationResult. |
| Primary components | ValidationResult, ValidationFailure, SaifValidationException |
| Entry point | src/SAIF.NetCore.Common/SAIF.NetCore.Common/SAIF.NetCore.Common/Types/ValidationResult.cs |
Steps¶
- Consumers add
ValidationFailureentries (PropertyName,ErrorMessage,AttemptedValue) toValidationResult.Errors, and informational strings toMessages. - Read
ValidationResult.IsValid, which istrueonly whenErrorscontains no entries. (BR-020) - Construct
SaifValidationExceptioneither directly from aValidationResult, or via the(propertyName, errorMessage)/(errorMessage)constructors, which build aValidationResultcontaining exactly one failure. - No constructor sets
Exception.Message, so the baseException.Messagedefault is used even though aValidationResultwith failure text is attached.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Validation logic runs]) --> AddFailures["Add ValidationFailure entries<br>to Errors / Messages"]
AddFailures --> CheckValid{Errors empty?}
CheckValid -->|Yes| Valid(["IsValid = true"])
CheckValid -->|No| Invalid(["IsValid = false"])
Invalid --> Construct["Construct SaifValidationException<br>from ValidationResult"]
Construct --> End([Throw to caller])
Failure and edge-case behavior¶
Messagesentries never affectIsValid; onlyErrorsdoes.SaifValidationExceptionnever sets its ownException.Message, so callers must inspectValidationResultrather than.Messagefor failure detail.
Related documentation¶
Sources¶
src/SAIF.NetCore.Common/SAIF.NetCore.Common/SAIF.NetCore.Common/Types/ValidationResult.cssrc/SAIF.NetCore.Common/SAIF.NetCore.Common/SAIF.NetCore.Common/Types/ValidationFailure.cssrc/SAIF.NetCore.Common/SAIF.NetCore.Common/SAIF.NetCore.Common/Types/SaifValidationException.cs