-
Notifications
You must be signed in to change notification settings - Fork 0
ClassValidation internals
A ClassValidationProfile gives the user the ability to define list of mappings. Each mapping is defined by type T. CreateMap returns a fluent IMappingExpression<T>. It allows users to create two types of mappings.
- map a property from T to an expression which takes T and an expression from
IValidatorExpression. - map a property from T to an expression which takes T and should return a boolean value, (basically allows a custom mapping expression)
MappingExpression => ForMember can create one of two types of objects from IObjectValidator<T>
-
ObjectValidator=> used for custom mapping expressions -
ClassObjectValidator=> used forIValidatorExpressionexpressions.
IValidatorExpression gives predefined expressions for the user to consume. Each property needs to have at least one mapping, if a user doesn't want it to be used the Ignore expression should be used.
ObjectValidator takes an optional errors message string
ClassObjectValidator the IValidatorExpression takes an optional error message string format text. Due to the expression func the optional param has to be passed in as null when defining a mapping.
This is the guts of the predefined expressions and implements IValidatorExpression. Both the regular validator and class validation use this under the hood.
This class uses ClassValidatorExpression and ValidationExpressionErrorMessageFactory to take the expressions and figure out error messages.
The factory is used to take the method signature being used by ClassValidatorExpression expression. It returns the string predefined message or override given, to be used in the string format, as well as possible values to be used in the string format.