Files
Readarr/src/Readarr.Http/Validation/EmptyCollectionValidator.cs
Stepan Goremykin 28f64d9a46 Migrate to FluentValidation 9
(cherry picked from commit 40e54685b9e83ed24a3979bfe965c453339ad02e)
2023-05-07 17:57:58 +03:00

24 lines
647 B
C#

using System.Collections.Generic;
using FluentValidation.Validators;
using NzbDrone.Common.Extensions;
namespace Readarr.Http.Validation
{
public class EmptyCollectionValidator<T> : PropertyValidator
{
protected override string GetDefaultMessageTemplate() => "Collection Must Be Empty";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return true;
}
var collection = context.PropertyValue as IEnumerable<T>;
return collection != null && collection.Empty();
}
}
}