Common
Common validations to all types
The only rule enforced by Typely
is that the value object cannot be created with a null value when the underlying type is a reference type. In this case, an ArgumentNullException
will be thrown. Default values are still allowed like 0 for int or "" for string. If you want the type to be set to a null value, make it nullable (MyType?
) or make the type a reference type with AsClass()
.
NotEmpty Validator
Ensures that the value is not an empty string or whitespace or the default value for value types, for example, 0 for int.
Example:
Example error: 'Name' must not be empty.
String format args:
Name
: Name of the type being validatedValue
: Current value of the property
NotEqual Validator
Ensures that the value is not equal to the specified value.
Example:
Example error: 'Name' should not be equal to 'value'.
String format args:
Name
: Name of the type being validatedValue
: Current value of the propertyComparisonValue
: Value that should not equal
Must Validator
Ensures that the value meets the specified condition.
Example:
Example error: The specified condition was not met for '{Name}'.
String format args:
Name
: Name of the type being validatedValue
: Current value of the property
Last updated