-
Notifications
You must be signed in to change notification settings - Fork 7
5. Validation
Jos de Weger edited this page Dec 23, 2018
·
1 revision
The following validations are provided out of the box:
-
IsRequired
(value can not be empty) -
Matches
(value must match regex pattern provided) -
WithMinimum
(value can not have value smaller than minimum provided) -
WithMaximum
(value can not have value bigger than maximum provided) -
ShouldHaveUniqueValue
(value has to be unique in column)
Besides these default validations, you can specify a custom validation with validation message:
new SheetMapper().AddConfigFor<TestModel>(cfg => cfg
.MapColumn(column => column
.WithHeader("Age")
.WithCustomRule<int>(x => x >= 18 && x <= 67, "Age should be between 3 and 5")
.MapTo(t => t.Age)));
If that still doesn't suit your needs, you can extend the library by implementing one of the following interfaces and writing extension methods:
- IParsingRule (these rules are validated during parsing of the cell value, e.g. IsRequiredRule)
- IComparableRule (these rules do some kind of comparison between values)
- IGenericRule
- IColumnRule (rules that relate to other values in the same column)