diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-25 18:46:13 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-01-25 18:46:13 -0600 |
| commit | 3834633fffc784bb06d4e69459c8c4748f0b6ae9 (patch) | |
| tree | 3496b8dbf2dc08770c0e48908f6703dfce58bfbe /src/slskd/Common | |
| parent | 5d0d9eff5b21c30563c125d54a1be88ca57b2398 (diff) | |
| download | slskd-3834633fffc784bb06d4e69459c8c4748f0b6ae9.tar.gz | |
document patch, add extension to validate
Diffstat (limited to 'src/slskd/Common')
| -rw-r--r-- | src/slskd/Common/Validation/Extensions.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/Extensions.cs b/src/slskd/Common/Validation/Extensions.cs index b7e396a3..6233d53b 100644 --- a/src/slskd/Common/Validation/Extensions.cs +++ b/src/slskd/Common/Validation/Extensions.cs @@ -44,5 +44,25 @@ namespace slskd.Validation return true; } + + /// <summary> + /// Validates options. + /// </summary> + /// <param name="patch">The options patch instance to validate.</param> + /// <param name="result">The result of the validation, if invalid.</param> + /// <returns>A value indicating whether the instance is valid.</returns> + public static bool TryValidate(this OptionsPatch patch, out CompositeValidationResult result) + { + result = null; + var results = new List<ValidationResult>(); + + if (!Validator.TryValidateObject(patch, new ValidationContext(patch), results, true)) + { + result = new CompositeValidationResult("Invalid configuration", results); + return false; + } + + return true; + } } }
\ No newline at end of file |
