1+ // using System;
2+ // using System.Collections.Concurrent;
3+ // using System.Collections.Generic;
4+ // using System.Linq;
5+ // using System.Threading;
6+ // using System.Threading.Tasks;
7+ // using FluentValidation;
8+ // using FluentValidation.Internal;
9+ // using FluentValidation.Results;
10+ // using FluentValidation.Validators;
11+ // using JetBrains.Annotations;
12+
13+ // namespace Rocket.Surgery.Extensions.FluentValidation
14+ // {
15+ // /// <summary>
16+ // /// PolymorphicPropertyValidator.
17+ // /// Implements the <see cref="NoopPropertyValidator" />
18+ // /// </summary>
19+ // /// <typeparam name="T"></typeparam>
20+ // /// <seealso cref="NoopPropertyValidator" />
21+ // public class PolymorphicPropertyValidator<T> : NoopPropertyValidator
22+ // {
23+ // private readonly IValidatorFactory _validatorFactory;
24+ // private readonly IServiceProvider _serviceProvider;
25+
26+ // /// <summary>
27+ // /// Initializes a new instance of the <see cref="PolymorphicPropertyValidator{T}" /> class.
28+ // /// </summary>
29+ // /// <param name="validatorFactory">The validator factory.</param>
30+ // /// <param name="serviceProvider">The service provider.</param>
31+ // internal PolymorphicPropertyValidator(IValidatorFactory validatorFactory, IServiceProvider serviceProvider)
32+ // {
33+ // _validatorFactory = validatorFactory;
34+ // _serviceProvider = serviceProvider;
35+ // }
36+
37+ // /// <summary>
38+ // /// Validates the specified context.
39+ // /// </summary>
40+ // /// <param name="context">The context.</param>
41+ // /// <returns>IEnumerable{ValidationFailure}.</returns>
42+ // public override IEnumerable<ValidationFailure> Validate([NotNull] PropertyValidatorContext context)
43+ // {
44+ // if (context == null)
45+ // {
46+ // throw new ArgumentNullException(nameof(context));
47+ // }
48+
49+ // // bail out if the property is null
50+ // if (context.PropertyValue == null || !( context.PropertyValue is T value ))
51+ // {
52+ // return Enumerable.Empty<ValidationFailure>();
53+ // }
54+
55+ // var validator = _validatorFactory.GetValidator(value.GetType());
56+ // if (context.ParentContext.IsChildCollectionContext)
57+ // {
58+ // return validator.Validate(context.ParentContext.CloneForChildValidator(value)).Errors;
59+ // }
60+
61+ // var validationContext = new ValidationContext<T>(
62+ // value,
63+ // PropertyChain.FromExpression(context.Rule.Expression),
64+ // context.ParentContext.Selector
65+ // );
66+ // validationContext.SetServiceProvider(_serviceProvider);
67+ // return validator.Validate(validationContext).Errors;
68+ // }
69+
70+ // /// <summary>
71+ // /// validate as an asynchronous operation.
72+ // /// </summary>
73+ // /// <param name="context">The context.</param>
74+ // /// <param name="cancellation">The cancellation.</param>
75+ // /// <returns>Task{IEnumerable{ValidationFailure}}.</returns>
76+ // public override async Task<IEnumerable<ValidationFailure>> ValidateAsync(
77+ // [NotNull] PropertyValidatorContext context,
78+ // CancellationToken cancellation
79+ // )
80+ // {
81+ // if (context == null)
82+ // {
83+ // throw new ArgumentNullException(nameof(context));
84+ // }
85+
86+ // // bail out if the property is null
87+ // if (context.PropertyValue == null || !( context.PropertyValue is T value ))
88+ // {
89+ // return Enumerable.Empty<ValidationFailure>();
90+ // }
91+
92+ // var validator = _validatorFactory.GetValidator(value.GetType());
93+ // if (context.ParentContext.IsChildCollectionContext)
94+ // {
95+ // return ( await validator.ValidateAsync(
96+ // context.ParentContext.CloneForChildValidator(value),
97+ // cancellation
98+ // ).ConfigureAwait(false) ).Errors;
99+ // }
100+
101+ // var validationContext = new ValidationContext<T>(
102+ // value,
103+ // PropertyChain.FromExpression(context.Rule.Expression),
104+ // context.ParentContext.Selector
105+ // );
106+ // validationContext.SetServiceProvider(_serviceProvider);
107+ // return ( await validator.ValidateAsync(validationContext, cancellation).ConfigureAwait(false) ).Errors;
108+ // }
109+ // }
110+ // }
0 commit comments