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에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET