TimeSpanValidator 클래스

정의

TimeSpan 개체의 유효성을 검사합니다.

public ref class TimeSpanValidator : System::Configuration::ConfigurationValidatorBase
public class TimeSpanValidator : System.Configuration.ConfigurationValidatorBase
type TimeSpanValidator = class
    inherit ConfigurationValidatorBase
Public Class TimeSpanValidator
Inherits ConfigurationValidatorBase
상속

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 TimeSpanValidator 형식입니다.

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

설명

클래스는 TimeSpanValidator 개체가 TimeSpan 특정 조건을 충족하는지 확인하는 데 사용됩니다. TimeSpanValidator 두 개의 매개 변수가 있는 생성자는 최소값과 최대 TimeSpan 값을 모두 준수합니다. 매개 변수가 TimeSpanValidator 세 개 있는 생성자는 최소값과 최대 TimeSpan 값 및 유효성 검사 범위가 배타적인지 여부를 모두 확인합니다. TimeSpanValidator 매개 변수가 4개인 생성자는 이전 세 개의 매개 변수를 확인하고 값이 TimeSpan 특정 시간(초)과 같은지 확인합니다.

CanValidate 메서드 유효성을 검사할 개체 형식에 필요한 형식과 일치 하는지 여부를 결정 합니다. 유효성 검사 중인 개체의 매개 변수로 전달 되는 Validate 메서드.

생성자

TimeSpanValidator(TimeSpan, TimeSpan)

제공된 매개 변수에 따라 TimeSpanValidator 클래스의 새 인스턴스를 초기화합니다.

TimeSpanValidator(TimeSpan, TimeSpan, Boolean)

제공된 매개 변수에 따라 TimeSpanValidator 클래스의 새 인스턴스를 초기화합니다.

TimeSpanValidator(TimeSpan, TimeSpan, Boolean, Int64)

제공된 매개 변수에 따라 TimeSpanValidator 클래스의 새 인스턴스를 초기화합니다.

메서드

CanValidate(Type)

개체 형식의 유효성을 검사할 수 있는지 여부를 확인합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
Validate(Object)

개체의 값이 유효한지 여부를 확인합니다.

적용 대상

추가 정보