TimeSpanValidator Classe
Definição
public ref class TimeSpanValidator : System::Configuration::ConfigurationValidatorBase
public class TimeSpanValidator : System.Configuration.ConfigurationValidatorBase
type TimeSpanValidator = class
inherit ConfigurationValidatorBase
Public Class TimeSpanValidator
Inherits ConfigurationValidatorBase
- Herança
Exemplos
O exemplo de código a seguir demonstra como usar o TimeSpanValidator tipo.The following code example demonstrates how to use the TimeSpanValidator type.
using System;
using System.Configuration;
namespace Samples.AspNet
{
class UsingTimeSpanValidator
{
static void Main(string[] args)
{
// Display title.
Console.WriteLine("ASP.NET Validators");
Console.WriteLine();
// Create TimeSpan and Validator.
TimeSpan testTimeSpan = new TimeSpan(0,1,05);
TimeSpan minTimeSpan = new TimeSpan(0,1,0);
TimeSpan maxTimeSpan = new TimeSpan(0,1,10);
TimeSpanValidator myTimeSpanValidator = new TimeSpanValidator(minTimeSpan, maxTimeSpan, false, 65);
// Determine if the object to validate can be validated.
Console.WriteLine("CanValidate: {0}",
myTimeSpanValidator.CanValidate(testTimeSpan.GetType()));
try
{
// Attempt validation.
myTimeSpanValidator.Validate(testTimeSpan);
Console.WriteLine("Validated.");
}
catch (ArgumentException e)
{
// Validation failed.
Console.WriteLine("Error: {0}", e.Message.ToString());
}
// Display and wait
Console.ReadLine();
}
}
}
Imports System.Configuration
Namespace Samples.AspNet
Class UsingStringValidator
Public Shared Sub Main()
' Display title.
Console.WriteLine("ASP.NET Validators")
Console.WriteLine()
' Create string and validator.
Dim testVal As String = "filename"
Dim myStrValidator As StringValidator = New StringValidator(1, 8, "$%^")
' Create TimeSpan and Validator.
Dim testTimeSpan As TimeSpan = New TimeSpan(0, 1, 5)
Dim minTimeSpan As TimeSpan = New TimeSpan(0, 1, 0)
Dim maxTimeSpan As TimeSpan = New TimeSpan(0, 1, 10)
Dim myTimeSpanValidator As TimeSpanValidator = _
New TimeSpanValidator(minTimeSpan, maxTimeSpan, False, 65)
' Determine if the object to validate can be validated.
Console.WriteLine("CanValidate: {0}", _
myTimeSpanValidator.CanValidate(testTimeSpan.GetType()))
Try
' Attempt validation.
myTimeSpanValidator.Validate(testTimeSpan)
Console.WriteLine("Validated.")
Catch e As Exception
' Validation failed.
Console.WriteLine("Error: {0}", e.Message.ToString())
End Try
' Display and wait.
Console.ReadLine()
End Sub
End Class
End Namespace
Comentários
A TimeSpanValidator classe é usada para garantir que um TimeSpan objeto atenda a critérios específicos.The TimeSpanValidator class is used to ensure that a TimeSpan object meets specific criteria. O TimeSpanValidator Construtor com dois parâmetros garante que um valor mínimo e um máximo TimeSpan sejam cumpridos.The TimeSpanValidator constructor with two parameters ensures that both a minimum and a maximum TimeSpan value are adhered to. O TimeSpanValidator Construtor com três parâmetros verifica os valores mínimo e máximo TimeSpan , bem como se o intervalo de validação é exclusivo.The TimeSpanValidator constructor with three parameters checks both the minimum and maximum TimeSpan values, as well as whether the validation range is exclusive. O TimeSpanValidator Construtor com quatro parâmetros verifica os três parâmetros anteriores e também verifica se o TimeSpan valor é igual a um número específico de segundos.The TimeSpanValidator constructor with four parameters checks the previous three parameters and also checks whether the TimeSpan value is equal to a specific number of seconds.
O CanValidate método determina se o tipo de objeto que está sendo validado corresponde ao tipo esperado.The CanValidate method determines whether the object type being validated matches the expected type. O objeto que está sendo validado é passado como um parâmetro do Validate método.The object being validated is passed as a parameter of the Validate method.
Construtores
| TimeSpanValidator(TimeSpan, TimeSpan) |
Inicializa uma nova instância da classe TimeSpanValidator, com base nos parâmetros fornecidos.Initializes a new instance of the TimeSpanValidator class, based on supplied parameters. |
| TimeSpanValidator(TimeSpan, TimeSpan, Boolean) |
Inicializa uma nova instância da classe TimeSpanValidator, com base nos parâmetros fornecidos.Initializes a new instance of the TimeSpanValidator class, based on supplied parameters. |
| TimeSpanValidator(TimeSpan, TimeSpan, Boolean, Int64) |
Inicializa uma nova instância da classe TimeSpanValidator, com base nos parâmetros fornecidos.Initializes a new instance of the TimeSpanValidator class, based on supplied parameters. |
Métodos
| CanValidate(Type) |
Determina se o tipo de objeto pode ser validado.Determines whether the type of the object can be validated. |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
| Validate(Object) |
Determina se o valor de um objeto é válido.Determines whether the value of an object is valid. |