Valit
Valit copied to clipboard
For(@object) throws exception when null
The for option should have a handled output with an error message, optionally a custom error message would be awesome.
void ValidateModel(RegisterModel model)
{
//Force exception
model = null;
var result = ValitRules<RegisterModel>
.Create()
.Ensure(m => m.Email, _=>_
.Required()
.Email())
.Ensure(m => m.Password, _=>_
.Required()
.MinLength(10))
.Ensure(m => m.Age, _=>_
.IsGreaterThan(16))
.For(model)
.Validate();
if(result.Succeeded)
{
// do something on success
}
else
{
// do something on failure
}
}