mirror of
https://github.com/bitwarden/server.git
synced 2025-05-12 07:02:16 -05:00

* Simplify and align CommandResult and ValidationResult. In particular, 1 error per Failure/Invalid. * Move these files to a common namespace * Remove unused code
21 lines
738 B
C#
21 lines
738 B
C#
using Bit.Core.AdminConsole.Utilities.Errors;
|
|
|
|
namespace Bit.Core.AdminConsole.Utilities.Validation;
|
|
|
|
public abstract record ValidationResult<T>;
|
|
|
|
public record Valid<T>(T Value) : ValidationResult<T>;
|
|
|
|
public record Invalid<T>(Error<T> Error) : ValidationResult<T>;
|
|
|
|
public static class ValidationResultMappers
|
|
{
|
|
public static ValidationResult<B> Map<A, B>(this ValidationResult<A> validationResult, B invalidValue) =>
|
|
validationResult switch
|
|
{
|
|
Valid<A> => new Valid<B>(invalidValue),
|
|
Invalid<A> invalid => new Invalid<B>(invalid.Error.ToError(invalidValue)),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(validationResult), "Unhandled validation result type")
|
|
};
|
|
}
|