fix(validation): make Severity meaningful in Validation.IsValid
Validation.IsValid previously counted every problem regardless of severity, leaving Severity inert. Now IsValid only fails on Error problems, so Warning and Info no longer invalidate the result, and IsValidFor(Severity) lets callers set the failing-severity threshold.
This commit is contained in:
parent
581b0a1ced
commit
15bf9a8e56
4 changed files with 75 additions and 3 deletions
|
|
@ -23,7 +23,27 @@ public sealed class Validation
|
|||
/// <summary>
|
||||
/// Whether the validation was successful.
|
||||
/// </summary>
|
||||
public bool IsValid => Problems.Count is 0;
|
||||
/// <remarks>
|
||||
/// A validation is considered successful unless it contains at least one problem with
|
||||
/// <see cref="Severity.Error"/>. Problems of lower severity (<see cref="Severity.Warning"/> or
|
||||
/// <see cref="Severity.Info"/>) do not invalidate the result. Use <see cref="IsValidFor"/>
|
||||
/// to control which severities are treated as failures.
|
||||
/// </remarks>
|
||||
public bool IsValid => IsValidFor(Severity.Error);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the validation was successful, treating problems at or above the given severity as failures.
|
||||
/// </summary>
|
||||
/// <param name="minimum">The minimum severity that should be considered a failure.</param>
|
||||
/// <remarks>
|
||||
/// A problem invalidates the validation when its <see cref="Severity"/> is at least as severe as
|
||||
/// <paramref name="minimum"/>. For example, <c>IsValidFor(Severity.Warning)</c> fails on errors and
|
||||
/// warnings but not on informational problems.
|
||||
/// </remarks>
|
||||
public bool IsValidFor(Severity minimum)
|
||||
{
|
||||
return !Problems.Any(problem => problem.Severity <= minimum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The problems that were found during validation.
|
||||
|
|
|
|||
Loading…
Reference in a new issue