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.v18.2.dll

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleRangeAttribute :
    RuleBaseAttribute,
    IRuleRangeProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties,
    IRuleSupportsCollectionAggregatesProperties
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True)>
Public Class RuleRangeAttribute
    Inherits RuleBaseAttribute
    Implements 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.

//...
private int age;
[RuleRange("",DefaultContexts.Save,35,45)]
public int Age {
   get { return age; }
   set { SetPropertyValue("Age", ref age, value); }
}
//...

The rule generated by the RuleRangeAttribute will be loaded to the Application Model's IModelValidationRules node. So, you can customize this rule via the Model Editor. In addition, you can create new rules in the Model Editor as well. This is helpful when you need to add a rule to a property which is implemented in a base class provided by a third party library. For details, refer to the Implement Property Value Validation in the Application Model topic.

You can see examples of using the RuleRange and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 18.2\Components\eXpressApp Framework\FeatureCenter folder, by default.

Inheritance

Object
Attribute
RuleBaseAttribute
RuleRangeAttribute

Implements

DevExpress.Persistent.Validation.IRuleBaseAttribute
DevExpress.Persistent.Validation.IRuleRangeProperties
DevExpress.Persistent.Validation.IRulePropertyValueProperties
See Also