TimeSpanValidatorAttribute Costruttore

Definizione

Inizializza una nuova istanza della classe TimeSpanValidatorAttribute.

public:
 TimeSpanValidatorAttribute();
public TimeSpanValidatorAttribute ();
Public Sub New ()

Esempio

Nell'esempio seguente viene illustrato come utilizzare il costruttore StringValidatorAttribute.


            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 '

Commenti

Questo costruttore viene usato nel modello con attributi per assicurarsi che il tipo del valore assegnato alla proprietà correlata sia un TimeSpan oggetto .

Si applica a