public bool IsDefault {get;組; }FluentValidation:如何將bool作爲必填字段以'false'作爲有效輸入?
RuleFor(stockImage => stockImage.IsDefault).NotNull();
我有這條規則,「IsDefault」布爾屬性應該不爲null。問題是,當客戶端在打api時沒有通過這個字段時,「IsDefault」將默認布爾屬性設置爲false,並且不會給出像「此字段是必需的」之類的任何錯誤。
我如何根據需要將此字段設置爲「真」或「假」作爲其唯一有效輸入?
一種解決方案,我試圖使情況:
RuleFor(stockImage => stockImage.IsDefault).NotEmpty();
問題在於,當「IsDefault」是「false」時,它會出現驗證錯誤,這不是預期的用例。
https://thedailywtf.com/articles/What_Is_Truth_0x3f_ – OffHeGoes