Relative Date Time 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: RelativeDateTImeValidator
Attribute Name: RelativeDateTimeValidatorAttribute
Configuration tool name: Relative Date Time Validator
Description
This validator checks that the DateTime value falls within a specified range using relative times and dates.
Properties
The following table lists the Relative Date Time Validator properties.
Relative Date Time Validator
Property |
Description |
---|---|
LowerBound |
This is the low-range boundary value. It must be of type Integer. The compiler checks this requirement if you directly invoke the validator in your code. If you use attributes or configuration, the application block throws an exception at run time if the type if incorrect. |
LowerBoundType |
This property determines how to evaluate the LowerBound value. Possible values for LowerBoundType are Ignore, Inclusive, and Exclusive. The Ignore value means that the validator ignores the LowerBound value. This is the default. The Inclusive value means that the validator allows values that are equal to the LowerBound value. The Exclusive value means that the validator does not allow values that are equal to the LowerBound value. |
LowerUnit |
This property sets the unit of time for the lower boundary. The possible values are None, Seconds, Minutes, Hours, Days, Months, and Years. The default is None. |
Negated |
This is a Boolean property. If it is set to True, it changes the validator's behavior so that it will fail if the condition is met, rather than when it is not met. The default is False. |
Tag |
This property is a user-supplied string. Typically, it is used to sort or categorize validation results that are in a log. |
UpperBound |
This is the upper-range boundary value. It must be type Integer. The compiler checks this requirement if you directly invoke the validator in your code. If you use attributes or configuration, the application block throws an exception at run time if the type if incorrect. |
UpperBoundType |
This property determines how to evaluate the UpperBound value. Possible values for LowerBoundType are Ignore, Inclusive, and Exclusive. The Ignore value means that the validator ignores the UpperBound value. This is the default. The Inclusive value means that the validator allows values that are equal to the UpperBound value. The Exclusive value means that the validator does not allow values that are equal to the UpperBound value. |
UpperUnit |
This property sets the unit of time for the upper boundary. The possible values are None, Seconds, Minutes, Hours, Days, Months, and Years. The default is None. |
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 validators with attributes and with code.
Attributes
The following code example attaches the RelativeDateTimeValidator attribute to the DateOfBirth property and checks to see if the user is 18 years or older.
public class Person
{
[RelativeDateTimeValidator(-120, DateTimeUnit.Year, -18, DateTimeUnit.Year,
Ruleset="RuleSetA", MessageTemplate="Must be 18 years or older.")]
public DateTime DateOfBirth
{
get
{
return dateOfBirth;
}
}
}
'Usage
Public Class Person
<RelativeDateTimeValidator(-120, DateTimeUnit.Year, -18, DateTimeUnit.Year, _
Ruleset = "RuleSetA", MessageTemplate = "Must be 18 years or older.")> _
Public ReadOnly Property DateOfBirth()
Get
Return _dateOfBirth
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. |