I have a class Property, which contains the following three Properties:
bool CorrespondanceAddressIsSecurityAddress
Address CorrespondanceAddress
Address SecurityAddress
The address class is just a basic address class that holds details about a user's address.
The user's correspondance address will always be filled in and therefore needs to be validated. The user has the option to select that their correspondance address is the same as their security address, when this occurs there is no need to validate the security address and it can be left as null.
What I would like to do is check the state of the CorrespondanceAddressIsSecurityAddress boolean and then set a validator for the security address if it is set to false, but I'm not sure of the syntax that is required to do this.
At the moment the class that controls the validation for the property class contains the two following lines:
RuleFor(p => p.CorrespondanceAddressIsSecurityAddress)
.NotNull()
.WithMessage("CorrespondanceAddressIsSecurityAddress cannot be null");
RuleFor(p => P.CorrespondanceAddressIsSecurityAddress
.Equals(false))
.SetValidator(new FluentAddressValidator());
However the second rule, which sets the validator gives a syntax error, saying
Cannot convert from '...FluentAddressValidator' to 'FluentValidation.Validators.IPropertyValidator
How do I go about setting a rule based on the value of a boolean?