I am trying to Validate that a Cron Expression is valid only when the property is not null
My code looks like this,
RuleFor(team => team.PlayTimeSlot)
.Must(IsValidSchedule)
.When(team => !string.IsNullOrEmpty(team.PlayTimeSlot));
public bool IsValidSchedule(string schedule)
{
// Some Schedule validation logic
}
However this does not work. What am I missing?
I would try to separate everything into methods as an alternative like this:
RuleFor(team => team.PlayTimeSlot)
.When(playTimeValid)
.Must(IsValidSchedule);
public bool isValidSchedule()
{
return true
}
public bool playTimeValid(TeamModel team)
{
if !string.isnullorempty(team.playtimeslot)
return true
}
Can you Try that with your code?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.