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
Співпраця з нами на GitHub
Джерело цього вмісту можна знайти на GitHub, де також можна створювати й переглядати запитання та запити на внесення змін. Докладні відомості наведено в нашому посібнику для співавторів.
Зворотний зв’язок
https://aka.ms/ContentUserFeedback.
Очікується незабаром: протягом 2024 року ми будемо припиняти використання механізму реєстрації проблем у GitHub для зворотного зв’язку щодо вмісту й замінювати його новою системою зворотного зв’язку. Докладніше:Надіслати й переглянути відгук про