| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="EmptyValidator.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Threading; |
| | | 9 | | using System.Threading.Tasks; |
| | | 10 | | using FluentValidation; |
| | | 11 | | using FluentValidation.Results; |
| | | 12 | | |
| | | 13 | | namespace MyNet.Observable.Validation.Validators; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// A validator that performs no validation and always returns a successful result. |
| | | 17 | | /// </summary> |
| | | 18 | | public sealed class EmptyValidator : IValidator |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// A singleton instance of the <see cref="EmptyValidator"/> that can be reused wherever a no-op validator is needed |
| | | 22 | | /// </summary> |
| | 3 | 23 | | public static readonly EmptyValidator Instance = new(); |
| | | 24 | | |
| | | 25 | | private EmptyValidator() |
| | | 26 | | { |
| | 3 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc/> |
| | 66 | 30 | | public ValidationResult Validate(IValidationContext context) => new(); |
| | | 31 | | |
| | | 32 | | /// <inheritdoc/> |
| | 0 | 33 | | public Task<ValidationResult> ValidateAsync(IValidationContext context, CancellationToken cancellation = default) => |
| | | 34 | | |
| | | 35 | | /// <inheritdoc/> |
| | 0 | 36 | | public IValidatorDescriptor CreateDescriptor() => new ValidatorDescriptor<object>([]); |
| | | 37 | | |
| | | 38 | | /// <inheritdoc/> |
| | 0 | 39 | | public bool CanValidateInstancesOfType(Type type) => true; |
| | | 40 | | } |
| | | 41 | | |