TimeSpanValidatorAttribute Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the TimeSpanValidatorAttribute class.
public:
TimeSpanValidatorAttribute();
public TimeSpanValidatorAttribute ();
Public Sub New ()
Examples
The following example shows how to use the StringValidatorAttribute constructor.
ConfigurationValidatorBase valBase;
TimeSpanValidatorAttribute tsValAttr;
tsValAttr = new TimeSpanValidatorAttribute();
TimeSpan goodValue = TimeSpan.FromMinutes(10);
Int16 badValue = 10;
try
{
valBase = tsValAttr.ValidatorInstance;
valBase.Validate(goodValue);
// valBase.Validate(badValue);
}
catch (ArgumentException e)
{
// Display error message.
string msg = e.ToString();
#if DEBUG
Console.WriteLine(msg);
#endif
}
Dim valBase As ConfigurationValidatorBase
Dim tsValAttr As TimeSpanValidatorAttribute
tsValAttr = New TimeSpanValidatorAttribute()
Dim goodValue As TimeSpan = TimeSpan.FromMinutes(10)
Dim badValue As Int16 = 10
Try
valBase = tsValAttr.ValidatorInstance
valBase.Validate(goodValue)
' valBase.Validate(badValue);
Catch e As ArgumentException
' Display error message.
Dim msg As String = e.ToString()
#If DEBUG Then
Console.WriteLine(msg)
#End If
End Try '
Remarks
You use this constructor in the attributed model to ensure that the type of the value assigned to the related property is a TimeSpan object.
Applies to
Tee yhteistyötä kanssamme GitHubissa
Tämän sisällön lähde on GitHubissa, jossa voit myös luoda ja tarkastella ongelmia ja pull-pyyntöjä. Katso lisätietoja osallistujan oppaasta.