And Composite Validator
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |
Class Name: AndCompositeValidator
Attribute Name: ValidatorCompositionAttribute
Configuration tool name: And Composite Validator
Description
This validator creates a composite validator. Validation requires that all the validators that make up the composite validator be true. For example, you can use the And Composite Validator to require that the Not Null Validator AND the Date Time Range Validator be True. Because the Validation Application Block's default behavior is to AND validators, you only need this validator to implement complex logic.
Properties
The And Composite Validator has a single property named Name. This is the name of the validator. The default name is And Composite Validator.
Example
The following code example shows the construction of an AndCompositeValidator instance using attributes. The validator combines a NotNullValidator and a StringLengthValidator. Note that this is the default behavior when more than one validator attribute is used. As a result, the ValidatorComposition attribute could be omitted.
public class Product
{
[ValidatorComposition(CompositionType.And)]
[NotNullValidator]
[StringLengthValidator(10)]
string _productCode;
public string GetProductCode( )
{
return _productCode;
}
// ...
}
'Usage
Public Class Product
<ValidatorComposition(CompositionType.And)> _
<NotNullValidator()> _
<StringLengthValidator(10)> _
Function GetProductCode() As String
Return _productCode
End Function
' ...
End Class