Hi, 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 string datatype) - "Name" and "Url". They both have the same amount of items, thus indexed items match up i.e., Names[0] correlates with Urls[0].
The only problem I am having is with validating empty items in each list. The rules i need are:
if an item is empty in Name[2] then Url[2] should not be empty. if an item is empty in Url[2] then Name[2] should not be empty. if they are both empty then we do not want to validate, we want to ignore.
note: I have used the index 2 in the above example but it could be anything
So far I have:
RuleFor(f => f.Names).Must(d => d.All(s => !String.IsNullOrEmpty(s)))
.WithMessage("Names cannot be empty.")
RuleFor(f => f.URLs).Must(urls => urls.All(s => !String.IsNullOrEmpty(s)))
.WithMessage("URLs cannot be empty.")
This checks that no items are empty in either list, however I need to be able to not validate items for being empty in one list if the correlating item in the other is also empty (If both are empty then we just want to ignore it).
Any ideas?