Ensures the value being validated is not null.
Value cannot be null.
Using type instance.
var validator = new ValidatorBuilder<string>()
.NotNull()
.Build();
var result = validator.Validate(null);
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.NotNull(e => e.FirstName)
.Build();
var result = validator.Validate(new Employee { FirstName = "Homer" });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.FirstName, v => v.NotNull())
.Build();
var result = validator.Validate(new Employee { LastName = "Simpson" });
Ensures the value being validated is null.
Value must be null.
Using type instance.
var validator = new ValidatorBuilder<string>()
.Null()
.Build();
var result = validator.Validate(null);
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.Null(e => e.FirstName)
.Build();
var result = validator.Validate(new Employee { FirstName = "Homer" });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.FirstName, v => v.Null())
.Build();
var result = validator.Validate(new Employee { LastName = "Simpson" });
Ensures the value being validated is equal to a specified value.
Value must equal '{other}'.
Using type instance.
var validator = new ValidatorBuilder<string>()
.Equal("Smithers")
.Build();
var result = validator.Validate("Smithers");
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.Equal(e => e.FirstName, "Homer")
.Build();
var result = validator.Validate(new Employee { FirstName = "Homer" });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.LastName, v => v.Equal("Smithers"))
.Build();
var result = validator.Validate(new Employee { LastName = "Simpson" });
Ensures the value being validated is not equal to a specified value.
Value must not equal '{other}'.
Using type instance.
var validator = new ValidatorBuilder<int>()
.NotEqual(17)
.Build();
var result = validator.Validate(18);
Using selector expression.
var validator = new ValidatorBuilder<Employee>()
.NotEqual(e => e.Age, 17)
.Build();
var result = validator.Validate(new Employee { Age = 18 });
Using For function.
var validator = new ValidatorBuilder<Employee>()
.For(e => e.Age, v => v.NotEqual(17))
.Build();
var result = validator.Validate(new Employee { Age = 18 });