Skip to content

ValidationRules class

namespace: Serenity.ComponentModel   assembly: Serenity.Net.Core

Finds the validation rules of a property, the forms' form of them, and checks them on the server. The rules are the ValidationAttributes of the property and the ones its other attributes imply, see IImpliesValidation. The Validate attributes, like ValidateRangeAttribute, are also checked by the forms, and so are the DataAnnotations attributes they derive from, which have the default messages of Serenity when they are not given one, while any other ValidationAttribute is only checked on the server.

public static class ValidationRules

Public Members

name description
static GetClientRule(…) Gets the rule the forms check for a validation attribute, or null when they don't check it, i.e. it is only checked on the server, or is not one they know.
static GetRules(…) Gets the validation rules among the attributes of a property, and the ones its other attributes imply.
static GetTextKeySuffix(…) Gets the suffix of the implied text key of the message of a rule, which follows the text key of its property, e.g. _ValidateRange for Db.Northwind.Customer.Quantity_ValidateRange, by the name of its attribute without Attribute, so a property can't have two rules with the same key, as an attribute of a rule can't be repeated. An attribute that allows being repeated, e.g. one rule class for several rules, also has the name of the rule, e.g. _ValidateClient_even, and two of them with the same rule need a TextKey each. Only the rules of Serenity have one, i.e. the ones that implement IClientValidationRule, as the messages of the DataAnnotations attributes are texts with the name of the field as {0}, not localizable texts.
static HasLocalizableMessage(…) Gets whether a rule has a message of its own, which is registered with its implied text key, see GetTextKeySuffix, i.e. it is a rule of Serenity with an ErrorMessage.
static Validate(…) Checks a value by a validation rule on the server, unless it is only checked by the forms.
static ValidateAsync(…) Checks a value by a validation rule on the server asynchronously, unless it is only checked by the forms. A rule that implements IAsyncValidationRule is awaited, and any other is checked synchronously, see Validate.
static ValidateObject(…) Validates the properties of an object by what the properties of its type, or of the RulesType, e.g. a form, declare: RequiredAttribute, RequiredWhenAttribute and the validation rules, like ValidateRangeAttribute. As in the browser, a property that is hidden, by VisibleAttribute, on insert or update, or by its VisibleWhenAttributes, or is read only, by ReadOnlyAttribute or its ReadOnlyWhenAttributes, is not checked, and neither is a rule only checked by the forms.
static ValidateObjectAsync(…) Validates the properties of an object like ValidateObject, awaiting the rules that can be checked asynchronously, see IAsyncValidationRule.

See Also