The requested page is not available for the requested platform. You are viewing the content for Default platform.

RuleValueComparisonAttribute Class

Defines a validation rule that demands the target property's value satisfy a specified condition.

Namespace: DevExpress.Persistent.Validation

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

Declaration

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleValueComparisonAttribute :
    RuleBaseAttribute,
    IRuleValueComparisonProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties,
    IRuleSupportsCollectionAggregatesProperties
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True)>
Public Class RuleValueComparisonAttribute
    Inherits RuleBaseAttribute
    Implements IRuleValueComparisonProperties,
               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 satisfies a specified condition. Use the operatorType parameter to specify the operator type that must be used when comparing values. The available values of this parameter are the ValueComparisonType enumeration values. Here they are:

  • Equals
  • GreaterThan
  • GreaterThanOrEqual
  • LessThan
  • LessThanOrEqual
  • NotEquals

Use the rightOperand parameter to specify the value to be compared with the target property's value.

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

Note

The RuleValueComparisonAttribute can be applied to properties of value types. To compare other type properties, use RuleStringComparisonAttribute and RuleCriteriaAttribute.

//...
private DateTime startDate;
[RuleValueComparison("",DefaultContexts.Save, ValueComparisonType.GreaterThan, "12/12/05")]
public DateTime StartDate {
   get { return startDate; }
   set { SetPropertyValue("StartDate", ref startDate, value); }
}
//...

The attribute constructor above expects a constant value as the rightOperand parameter. To refer to a property of the current object (or to compare with a calculated expression), set the mode parameter to ParametersMode.Expression using the following constructor.

[RuleValueComparison("", DefaultContexts.Save, ValueComparisonType.GreaterThan,
    "OrderDateTime", ParametersMode.Expression)]

The rule generated by the RuleValueComparisonAttribute 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 RuleValueComparison and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 19.1\Components\eXpressApp Framework\FeatureCenter folder, by default.

Inheritance

Object
Attribute
RuleBaseAttribute
RuleValueComparisonAttribute

Implements

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