Skip to main content
.NET 8.0+

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

RuleSet Class

Specifies a set of Validation Rules that can be checked against an object.

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v25.1.dll

#Declaration

public class RuleSet :
    IRuleSet,
    IEnumerable<IRule>,
    IEnumerable

The following members return RuleSet objects:

#Remarks

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.

#How to Subscribe to Validation Events in a .NET Application

You can use the ValidationOptions class to handle validation events in .NET applications. The ValidationOptions.Events property exposes the following delegate properties:

  • OnCustomIsEmptyValue
  • OnCustomIsEmptyValueType
  • OnCustomNeedToValidateRule
  • OnCustomValidateRule
  • OnRuleValidated
  • OnValidationCompleted

You can assign event handlers to their properties in two ways: use the XAF Application Builder or get a ValidationOptions instance as IOptionsSnapshot.

#Use the XAF Application Builder

The following code sample subscribes to the OnCustomNeedToValidateRule event in the XAF Application Builder:

C#
services.AddXaf(Configuration, builder => {
    //...
    builder.Modules
        //...
        .AddValidation(options => {
            options.Events.OnCustomNeedToValidateRule += (context) => {
                //...
            };
        });
    //...
};

#Get a ValidationOptions instance as IOptionsSnapshot

The following code sample uses dependency injection and IOptionsSnapshot to subscribe to the OnCustomNeedToValidateRule event in an XAF controller:

C#
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) {
        //...
    }
}

#Implements

#Inheritance

Object
RuleSet
See Also