Search code examples
c#fluentvalidation

Fluent Validation for enum type required field


I have a simple enum for validation form.

Painting type is a required field , so I want to make rule for them in Fluent Validator.What should i specify .NotNull() or .NotEmpty()?

public enum VehiclePaintingType
{
    Pearly = 1,
    Metallic,
    Opaque     
}

Solution

  • As pointed out by Scrobi (and according to the docs), .NotNull() ensures that the specified property is not null, while .NotEmpty() ensures that it is not null, an empty string or a whitespace. So, for your case, it is best to use .NotEmpty().