using Atomx.Admin.Client.Models; using FluentValidation; using Microsoft.Extensions.Localization; namespace Atomx.Admin.Client.Validators { public class ManufacturerModelValidator : AbstractValidator { public ManufacturerModelValidator(IStringLocalizer localizer) { RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空"); } public Func>> ValidateValue => async (model, propertyName) => { var result = await ValidateAsync(ValidationContext.CreateWithOptions((ManufacturerModel)model, x => { x.IncludeProperties(propertyName); })); if (result.IsValid) return Array.Empty(); return result.Errors.Select(e => e.ErrorMessage); }; } }