Class ValidationRule<TProperties, TClientProperties, TValue>
Represents a base class for validation rules with custom client properties.
public abstract class ValidationRule<TProperties, TClientProperties, TValue> : IValidationRule where TProperties : ValidationRuleProperties, new() where TClientProperties : ValidationRuleClientProperties, new()
Type Parameters
TProperties
Type of the rule configurable properties.
TClientProperties
Type of the rule client properties.
TValue
Value to be validated.
- Inheritance
-
objectValidationRule<TProperties, TClientProperties, TValue>
- Implements
- Derived
- Extension Methods
Remarks
Validation rules registered with RegisterFormValidationRuleAttribute attribute
that have TProperties
property fields annotated with FormComponentAttribute
attribute are editable in the Validation Rules section of the field editor.
Constructors
ValidationRule()
Initializes a new instance of the ValidationRule<TProperties, TClientProperties, TValue> class.
protected ValidationRule()
Properties
ClientRuleName
Gets the client rule name identifier.
public abstract string ClientRuleName { get; }
Property Value
- string
DefaultErrorMessage
Defines default error message of the validation rule.
protected virtual string DefaultErrorMessage { get; }
Property Value
- string
ErrorMessageFormatter
Defines a formatter function for error message.
protected virtual Func<string, string> ErrorMessageFormatter { get; }
Property Value
- Func<string, string>
Remarks
Formatter is applied for DefaultErrorMessage or ErrorMessage. The custom error message defined by ErrorMessage is considered as a localized and formatted by the caller.
Properties
Contains values of configurable properties for the validation rule.
public TProperties Properties { get; }
Property Value
- TProperties
Remarks
Validation rules registered with RegisterFormValidationRuleAttribute attribute that property fields annotated with FormComponentAttribute attribute are editable in the Validation Rules section of the field editor.
Result
Represents a result of Validate(object, IFormFieldValueProvider) method.
public ValidationResult Result { get; protected set; }
Property Value
Remarks
Result is set by Validate(TValue, IFormFieldValueProvider) method and shouldn't be set directly by the validation rule except the custom initial value within the validation rule constructor.
Methods
ConfigureClientProperties(TClientProperties)
Allows set validation rule client properties.
protected virtual Task ConfigureClientProperties(TClientProperties clientProperties)
Parameters
clientProperties
TClientPropertiesCurrent instance of client properties.
Returns
- Task
Validate(TValue, IFormFieldValueProvider)
Validates value
and returns the validation result.
public abstract Task<ValidationResult> Validate(TValue value, IFormFieldValueProvider formFieldValueProvider)
Parameters
value
TValueValue to be validated.
formFieldValueProvider
IFormFieldValueProviderProvider of values of other form fields for contextual validation.
Returns
- Task<ValidationResult>
Returns validation result with IsValid set to true, if value is valid. Otherwise returns result with the flag set to false and a corresponding error message.