小编AHM*_*MAD的帖子

fluentvalidation SetCollectionValidator

Dears我正在尝试使用SetCollectionValidator验证对象列表,并且列表计数可能有0个对象或更多的对象,所以验证返回错误,直到列表没有像这样的项目

public class SCRequest
{
    public List<Attachment> Attachments { get; set; }
}

public class Attachment
{
    public int AttachmentId { get; set; }
    public string Name { get; set; }
    public string FileType { get; set; }
    public string FilePath { get; set; }
    public string FileUrl { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

现在用于验证ScRequest我做以下事情

public SCRequestValidator()
{
    RuleFor(request => request.Attachments)
        .SetCollectionValidator(new AttachmentValidator());
}
Run Code Online (Sandbox Code Playgroud)

并且为了验证附件,我执行以下操作

public AttachmentValidator()
{
    RuleFor(x => x.FileUrl)
        .NotNull()
        .WithMessage(ErrorMessage.B0001)
        .NotEmpty()
        .WithMessage("Not Allowed Empty");
}
Run Code Online (Sandbox Code Playgroud)

我没有 …

c# fluentvalidation

1
推荐指数
1
解决办法
1793
查看次数

标签 统计

c# ×1

fluentvalidation ×1