Share via


Or Composite Validator

Class Name: OrCompositeValidator

Attribute Name: ValidatorCompositionAttribute

Configuration tool name: Or Composite Validator

Description

This validator creates a composite validator. Validation requires that at least one of the validators that make up the composite validator be True. For example, you can use the Or composite validator to require that the Not Null validator OR the date time range validator be True.

Properties

The following table lists the Or composite validator properties. The actual property names shown in the configuration tools are listed in the table description.

Property

Description

MessageTemplate

MessageTemplate - This property is a string containing template tokens that the validator replaces with values as it validates the target. Typically, it describes the validation result.

MessageTemplateResourceName

Template Resource Name - If you do not want to use the MessageTemplate property to hard-code a message template (perhaps for internationalization), you can use a template stored in the application resources. You must also specify a MessageTemplateResourceType value. If you include both a MessageTemplate value and a MessageTemeplateResourceName value, the MessageTemplate value takes precedence.

MessageTemplateResourceType

Template Resource Type - The resource type for the template you want to use. If you specify a MessageTemplateResourceName value, you must specify this value.

Name

Name – The name to use for this validator.

Tag

This property is a user-supplied string. Typically, it is used to sort or categorize validation results.

TypeName

Type Name – The fully qualified name of the type configuration element. This property cannot be edited.

Example

The following example shows how to use the validators with attributes. The validator combines a NotNullValidator and a StringLengthValidator.

public class Product
{
  [ValidatorComposition(CompositionType.Or)]
  [NotNullValidator]
  [StringLengthValidator(10)]
  public string ProductCode
  {
    get
    {
      return _productCode;
    }
  }
  // ...
}
'Usage
Public Class Product
  <ValidatorComposition(CompositionType.Or)> _
  <NotNullValidator()> _
  <StringLengthValidator(10)> _
  ReadOnly Property ProductCode(ByVal _productCode As String)
    Get
      Return _productCode
    End Get
  End Property
  ' ...
End Class