Object 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: ObjectValidator
Attribute Name: ObjectValidatorAttribute
Configuration tool name: Object Validator
Description
This validator causes validation to occur on an object reference. All validators defined for the object's type will be invoked, just as if the Validation.Validate method had been called on the object. If the object you want to validate is null, the validation is ignored. If the reference is to an instance of a type that is not compatible with the configured target's type then the validation fails. This validator is helpful for validating tree-structured data.
Properties
The following table lists the Object Validator properties.
Object Validator Properties
Property |
Description |
---|---|
Tag |
This property is a user-supplied string. Typically, it is used to sort or categorize validation results that are in a log. |
TargetRuleset |
This is the name of the rule set that will be applied to the object. |
MessageTemplate |
This property is a user-supplied string. Typically, it describes the validation result and is intended for a log. |
MessageTemplateResourceName |
If you do not want to use the MessageTemplate property to specify a message, you can use another template by specifying it with the MessageTemplateResourceName value. If you include both a MessageTemplate value and a MessageTemplateResourceName value, the MessageTemplate value takes precedence. |
MessageTemplateResourceTypeName |
If you specify a MessageTemplateResourceName value then you must specify a MessageTemplateResourceTypeName value, which is the type of the template you want to use. |
Examples
The following examples show how to use the validator with attributes and with code.
Attributes
The following code example checks that the Part object that is returned by the OrderedPart property meets the requirements of the Part class' validator. The Part class' validator checks that the name is fewer than 20 characters and that the manufacturer URL is well formed according to a particular regular expression pattern.
public class Part
{
[StringLengthValidator(20)]
string name;
[RegexValidator("http://(www\.)?([^\.]+)\.com")]
string manufacturerUrl;
// ...
}
public class OrderLineItem
{
[NotNullValidator]
[ObjectValidator]
public Part OrderedPart
{
get
{
return partList;
}
}
// ...
}
'Usage
Public Class Part
<StringLengthValidator(20)> _
Dim name As String
<RegexValidator("http://(www\.)?([^\.]+)\.com")> _
Dim manufacturerUrl As String
' ...
End Class
Public Class OrderLineItem
<NotNullValidator()> _
<ObjectValidator()> _
ReadOnly Property OrderedPart(ByVal partList As String)
Get
Return partList
End Get
End Property
' ...
End Class
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. |