I am testing PUT with two string :
company.CurrencyCode = request.CurrencyCode ?? company.CurrencyCode; company.CountryIso2 = request.Country ?? company.CountryIso2;
and I tried using a rule like:
public UpdateCompanyValidator() { RuleSet(ApplyTo.Put, () => { RuleFor(r => r.CountryIso2) .Length(2) .When(x => !x.Equals(null)); RuleFor(r => r.CurrencyCode) .Length(3) .When(x => !x.Equals(null)); }); }
since I don't mind to get null for these properties, but I would like to check the Length when the property is not null .
What is the best way to apply the rules when the property is nullable and we just want to check if it is null?
c # fluentvalidation
balexandre
source share