我一般都是FluentValidation的新手。我寫了一個驗證器,我似乎無法弄清楚如何使用WarningMessage而不是ErrorMessage來完成.WithMessage並使用參數。使用帶有WarningMessage參數的FluentValidation的WithMessage方法
我可以這樣做:
RuleFor(x => x.Endorsement)
.Must((coverage, endorsement) => HaveCoveragePerAcreOverMinimum(_coverage, coverage))
.When(x => (!HaveSpecialRequest(_coverage) && !HavePermissionsToOverrideLimits()))
.WithMessage("Some error message {0}", x => x.MyError);
但是,將其設置爲一個的ErrorMessage,我需要一個警告消息。我試過,但沒有骰子:
RuleFor(x => x.Endorsement)
.Must((coverage, endorsement) => HaveCoveragePerAcreOverMinimum(_coverage, coverage))
.When(x => (!HaveSpecialRequest(_coverage) && !HavePermissionsToOverrideLimits()))
.WithMessage(new WarningMessage("Some warning message {0}", x => x.MyError));