[英]FluentValidation - Check value is an expression only if the value is not null
我正在尝试验证 Cron 表达式仅在属性不是 null 时才有效
我的代码看起来像这样,
RuleFor(team => team.PlayTimeSlot)
.Must(IsValidSchedule)
.When(team => !string.IsNullOrEmpty(team.PlayTimeSlot));
public bool IsValidSchedule(string schedule)
{
// Some Schedule validation logic
}
但是,这不起作用。 我错过了什么?
我会尝试将所有内容分成方法作为替代方法,如下所示:
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
}
你能用你的代码试试吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.