expressappframework-devexpress-dot-persistent-dot-validation-0dd4586c.md
Specifies a set of Validation Rules that can be checked against an object.
Namespace : DevExpress.Persistent.Validation
Assembly : DevExpress.Persistent.Base.v25.2.dll
NuGet Package : DevExpress.Persistent.Base
public class RuleSet :
IRuleSet,
IEnumerable<IRule>,
IEnumerable
Public Class RuleSet
Implements IRuleSet,
IEnumerable(Of IRule),
IEnumerable
The following members return RuleSet objects:
Note
This is a legacy class. In new applications that target .NET, use IRuleSet instead. Note that IRuleSet does not contains validation events. Refer to the following section to learn how to subscribe to RuleSet events in .NET.
Validation is based on rules declared in business class code and in the Validation node of the Application Model. These rules are automatically collected in the RegisteredRules property of the RuleSet object. The validation module’s engine checks rules when saving and deleting objects and when an Action with the corresponding validation context is executed.
You should not create instances of the RuleSet class manually, because if you validate a custom RuleSet, rules from the default set are ignored and the validation result may be invalid.
You can use the ValidationOptions class to handle validation events. The ValidationOptions.Events property exposes the following delegate properties:
OnCustomIsEmptyValueOnCustomIsEmptyValueTypeOnCustomNeedToValidateRuleOnCustomValidateRuleOnRuleValidatedOnValidationCompletedYou can assign event handlers to their properties in two ways: use the XAF Application Builder or get a ValidationOptions instance as IOptionsSnapshot.
The following code sample subscribes to the OnCustomNeedToValidateRule event in the XAF Application Builder:
services.AddXaf(Configuration, builder => {
//...
builder.Modules
//...
.AddValidation(options => {
options.Events.OnCustomNeedToValidateRule += (context) => {
//...
};
});
//...
};
The following code sample uses dependency injection and IOptionsSnapshot to subscribe to the OnCustomNeedToValidateRule event in an XAF controller:
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Validation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
public class CustomValidationCheckController : WindowController {
IOptionsSnapshot<ValidationOptions> options;
[ActivatorUtilitiesConstructor]
public CustomValidationCheckController(IServiceProvider serviceProvider) : this() {
this.TargetWindowType = WindowType.Main;
options = serviceProvider.GetRequiredService<IOptionsSnapshot<ValidationOptions>>();
}
public CustomValidationCheckController() { }
protected override void OnActivated() {
base.OnActivated();
options.Value.Events.OnCustomNeedToValidateRule += CustomNeedToValidateRule;
}
protected override void OnDeactivated() {
options.Value.Events.OnCustomNeedToValidateRule -= CustomNeedToValidateRule;
base.OnDeactivated();
}
private void CustomNeedToValidateRule(CustomNeedToValidateRuleContext context) {
//...
}
}
Object RuleSet
See Also