1
我想在FluentValidation中實現一個複雜的驗證方案。使用FluentValidation爲多個屬性創建驗證規則
比方說,我有一個汽車類。它有四個屬性:顏色,品牌,型號,年份。
我想構建一個驗證規則,涉及其中三個屬性。對於談話的緣故,讓我們說,我想類似下面的驗證規則:
if car.make = nissan and car.year = 2010 then
if car.color <> green then
throw a validation error since the system does not support 2010 nissans that are not green.
end
end
我知道這是一個愚蠢的例子。然而,我的應用程序中有驗證規則,涉及我的對象的多個方面。這是我的問題的核心。
我試圖遵循http://fluentvalidation.codeplex.com/wikipage?title=Custom關於使用「使用AbstractValidator.Custom」的指導。
有沒有人有其他工作的AbstractValidator.Custom工作的例子?
提前感謝您的時間。