|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using FluentValidation;
|
|
|
|
using FluentValidation;
|
|
|
|
using FluentValidation.Internal;
|
|
|
|
using FluentValidation.Internal;
|
|
|
|
|
|
|
|
using FluentValidation.Resources;
|
|
|
|
using NzbDrone.Api.ClientSchema;
|
|
|
|
using NzbDrone.Api.ClientSchema;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
@ -10,10 +11,11 @@ namespace NzbDrone.Api.REST
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ResourceValidator<TResource> : AbstractValidator<TResource>
|
|
|
|
public class ResourceValidator<TResource> : AbstractValidator<TResource>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public IRuleBuilderInitial<TResource, TProperty> RuleForField<TProperty>(Expression<Func<TResource, IEnumerable<Field>>> fieldListAccessor, string filedName)
|
|
|
|
public IRuleBuilderInitial<TResource, TProperty> RuleForField<TProperty>(Expression<Func<TResource, IEnumerable<Field>>> fieldListAccessor, string fieldName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var rule = new PropertyRule(fieldListAccessor.GetMember(), c => GetValue(c, fieldListAccessor.Compile(), filedName), null, () => { return CascadeMode.Continue; }, typeof(TProperty), typeof(TResource));
|
|
|
|
var rule = new PropertyRule(fieldListAccessor.GetMember(), c => GetValue(c, fieldListAccessor.Compile(), fieldName), null, () => CascadeMode.Continue, typeof(TProperty), typeof(TResource));
|
|
|
|
rule.PropertyName += "." + filedName;
|
|
|
|
rule.PropertyName += "." + fieldName;
|
|
|
|
|
|
|
|
rule.DisplayName = new StaticStringSource(fieldName);
|
|
|
|
|
|
|
|
|
|
|
|
AddRule(rule);
|
|
|
|
AddRule(rule);
|
|
|
|
return new RuleBuilder<TResource, TProperty>(rule);
|
|
|
|
return new RuleBuilder<TResource, TProperty>(rule);
|
|
|
|