Validate 2 lists using FluentValidation

后端 未结 2 675
甜味超标
甜味超标 2021-02-10 04:21

if anyone has much experience using [C#] FluentValidation and has any ideas for the below question any help would be much appreciated.

I have 2 Generic Lists (both with

2条回答
  •  有刺的猬
    2021-02-10 05:03

    Here is some Pseudo-code of a brute force solution. (I cannot think of any LINQ way of doing indexed comparisions) Sorry for the butchering of Fluent syntax.

    Must(Names.Length == URLs.Length).WithMessage("Names must be equal in size to URLs");
    for (int i = 0; i < Name.Length; i++)
    {
        Must(string.IsNullOrEmpty(Names[i]) ^^ string.IsNullOrEmpty(URLs[i])).WithMessage("Either Name and URL must be non-empty, or both must be empty, index = " + i);
    }
    

    Hopefully you get the gist of it, you may also want to look into general LINQ methods, there is likely one that I missed. Basically you are wanting to do a join, and then check for invalid results in the merged list, but again I am unsure how to do a row by row and not simply a many to many join.

提交回复
热议问题