.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

RuleRangeAttribute Class

Defines a validation rule that demands the target property’s value be within the specified value range (including the range’s end points).

Namespace: DevExpress.Persistent.Validation

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

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleRangeAttribute :
    RuleBaseAttribute,
    IRuleRangeProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties,
    IRuleSupportsCollectionAggregatesProperties

Remarks

Apply this attribute to a business class property to define a validation rule that will check whether this property’s value is within the specified range. Use the minimalValue and maximumValue parameters to specify the start and end points of the target property value’s range. These parameter values must be the same type as the property or a value type that implements the IComparable interface; otherwise, an ArgumentException is thrown.

You can use Function Criteria Operators as the minimalValue and maximumValue parameter values. For instance, you can pass the LocalDateTimeLastWeek() and LocalDateTimeToday parameters to check whether the target property’s value is set to a date from last week.

When applying this attribute, use common parameters that are inherited from the RuleBaseAttribute class, in addition to the specific parameters.

using System;
using DevExpress.Persistent.Validation;
//...
private DateTime lastSevenDays;
[RuleRange("LastSevenDays_RuleRange", "Save", "AddDays(LocalDateTimeToday(), -7)", 
    "LocalDateTimeToday()", ParametersMode.Expression)]
public DateTime LastSevenDays {
    get { return lastSevenDays; }
    set { SetPropertyValue(nameof(LastSevenDays), ref lastSevenDays, value); }
}
//...

The rule generated by the RuleRangeAttribute will be loaded to the Application Model‘s IModelValidationRules node. You can customize this rule with the Model Editor. You can also create new rules in the Model Editor. This is helpful when you need to add a rule to a property that is implemented in a base class supplied by a third party library. Refer to the following topic for details: Implement Property Value Validation in the Application Model.

You can see examples of how to use the RuleRange and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 21.1\Components.NET Core Desktop Libraries\eXpressApp Framework\FeatureCenter folder.

Inheritance

See Also