I have a bool along with a null DateTime property. DateTime is only required if bool is set to true ... And I want to check the date if bool is true.
I have this expression so far ...
When(p => p.HasVisa == true, () => RuleFor(p => p.VisaExpiryDate).NotNull());
Now I'm trying to check the date in this expression using the .Must extension and my custom BeAValidDate method ...
When(p => p.HasVisa == true, () => RuleFor(p => p.VisaExpiryDate).NotNull().Must(BeAValidDate)); private bool BeAValidDate(DateTime date) { if (date == default(DateTime)) return false; return true; }
But the .Must extension does not allow me to work with DateTime, which is null. How can I perform such a check on a zero date?
thanks
source share