Back to Devexpress

RuleStringComparisonAttribute Class

expressappframework-devexpress-dot-persistent-dot-validation-dfa8e31a.md

latest4.6 KB
Original Source

RuleStringComparisonAttribute Class

Defines a validation rule that demands the target string type property’s value satisfy a specified condition.

Namespace : DevExpress.Persistent.Validation

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

NuGet Package : DevExpress.Persistent.Base

Declaration

csharp
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RuleStringComparisonAttribute :
    RuleBaseAttribute,
    IRuleStringComparisonProperties,
    IRulePropertyValueProperties,
    IRuleCollectionPropertyProperties,
    IRuleBaseProperties
vb
<AttributeUsage(AttributeTargets.Property, AllowMultiple:=True)>
Public Class RuleStringComparisonAttribute
    Inherits RuleBaseAttribute
    Implements IRuleStringComparisonProperties,
               IRulePropertyValueProperties,
               IRuleCollectionPropertyProperties,
               IRuleBaseProperties

Remarks

Apply this attribute to a business class string 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 string values. The available values of this parameters are the StringComparisonType enumeration values. Here they are:

  • Contains
  • EndsWith
  • Equals
  • NotEquals
  • StartsWith

Use the operandValue parameter, to specify the value to be compared with the target property’s value. In addition, use the common parameters that are inherited from the RuleBaseAttribute class.

csharp
[RuleStringComparison("",DefaultContexts.Save,StringComparisonType.StartsWith,"A",IgnoreCase=true)]
public virtual string Name { get; set; }
//...
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
csharp
//...
private string name;
[RuleStringComparison("",DefaultContexts.Save,StringComparisonType.StartsWith,"A",IgnoreCase=true)]
public string Name {
   get { return name; }
   set { SetPropertyValue(nameof(Name), ref name, value); }
}
//...

The rule generated by the RuleStringComparisonAttribute 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 topic.

You can see examples of using the RuleStringComparison and other validation attributes in the Validation section of the FeatureCenter demo. This demo is located in the %PUBLIC%\Documents\DevExpress Demos 25.2\Components\XAF\FeatureCenter.NET.XPO folder, by default.

Implements

IRuleCollectionPropertyProperties

IRuleBaseProperties

Inheritance

Object Attribute RuleBaseAttribute RuleStringComparisonAttribute

See Also

RuleStringComparisonAttribute Members

Validation Rules

DevExpress.Persistent.Validation Namespace