IntegerValidator 클래스

정의

Int32 값의 유효성을 검사합니다.

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

예제

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

using System;
using System.Configuration;

namespace Microsoft.Samples.AspNet.Validators
{
    class UsingIntegerValidator
    {
        static void Main(string[] args)
        {
            // Display title.
            Console.WriteLine("ASP.NET Validators");
            Console.WriteLine();

            Console.WriteLine(
                "Set mininum and maximum of 1 and 10 inclusive");

            // Create Validator for the range of 1 to 10 inclusive
            int minIntVal = 1;
            int maxIntVal = 10;
            bool exclusive = false;
            IntegerValidator integerValidator =
                new IntegerValidator(minIntVal, maxIntVal, exclusive);

            int testInt = 0;
            ValidateInteger(integerValidator, testInt);
            testInt = 1;
            ValidateInteger(integerValidator, testInt);
            testInt = 5;
            ValidateInteger(integerValidator, testInt);

            Console.WriteLine();
            Console.WriteLine(
                "Set mininum and maximum of 1 and 10 exclusive");

            // Create Validator for the range of 1 to 10 exclusive
            exclusive = true;
            integerValidator =
                new IntegerValidator(minIntVal, maxIntVal, exclusive);

            testInt = 0;
            ValidateInteger(integerValidator, testInt);
            testInt = 1;
            ValidateInteger(integerValidator, testInt);
            testInt = 5;
            ValidateInteger(integerValidator, testInt);

            Console.WriteLine();
            Console.WriteLine(
                "Determine if an object to validate can be validated.");

            object testObjectToValidate = "a";
            Console.WriteLine("Can validate object of type {0}: {1}",
                testObjectToValidate.GetType(),
                integerValidator.CanValidate(testObjectToValidate.GetType()));
            testObjectToValidate = new int();
            Console.WriteLine("Can validate object of type {0}: {1}",
                testObjectToValidate.GetType(),
                integerValidator.CanValidate(testObjectToValidate.GetType()));

            // Leave output on screen until enter is pressed.
            Console.ReadLine();
        }

        private static void ValidateInteger(IntegerValidator integerValidator, int valuetoValidate)
        {
            Console.Write("Validating integer value of {0}:  ", valuetoValidate);
            try
            {
                integerValidator.Validate(valuetoValidate);
                Console.WriteLine("Validated.");
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Failed validation.  Message: {0}", e.Message.ToString());
            }
        }
    }
}
Imports System.Configuration

Namespace Microsoft.Samples.AspNet.Validators
    Module UsingIntegerValidator
        Public Sub Main()

            ' Display title.
            Console.WriteLine("ASP.NET Validators")
            Console.WriteLine()

            Console.WriteLine( _
                "Set mininum and maximum of 1 and 10 inclusive")

            ' Create Validator for the range of 1 to 10 inclusive
            Dim minIntVal As Int32 = 1
            Dim maxIntVal As Int32 = 10
            Dim exclusive As Boolean = False
            Dim validator As IntegerValidator = _
                New IntegerValidator(minIntVal, maxIntVal, exclusive)

            Dim testInt As Integer = 0
            ValidateInteger(validator, testInt)
            testInt = 1
            ValidateInteger(validator, testInt)
            testInt = 5
            ValidateInteger(validator, testInt)

            Console.WriteLine()
            Console.WriteLine( _
                "Set mininum and maximum of 1 and 10 exclusive")

            ' Create Validator for the range of 1 to 10 exclusive
            exclusive = True
            validator = _
                New IntegerValidator(minIntVal, maxIntVal, exclusive)

            testInt = 0
            ValidateInteger(validator, testInt)
            testInt = 1
            ValidateInteger(validator, testInt)
            testInt = 5
            ValidateInteger(validator, testInt)

            Console.WriteLine()
            Console.WriteLine( _
                "Determine if an object to validate can be validated.")

            Dim testObjectToValidate As Object = "a"
            Console.WriteLine("Can validate object of type {0}: {1}", _
                testObjectToValidate.GetType(), _
                validator.CanValidate(testObjectToValidate.GetType()))
            testObjectToValidate = New Integer()
            Console.WriteLine("Can validate object of type {0}: {1}", _
                testObjectToValidate.GetType(), _
                validator.CanValidate(testObjectToValidate.GetType()))

            ' Leave output on screen until enter is pressed.
            Console.ReadLine()
        End Sub

        Sub ValidateInteger(ByVal validator As IntegerValidator, ByVal valueToValidate As Integer)
            Console.Write("Validating integer value of {0}:  ", valueToValidate)
            Try
                validator.Validate(valueToValidate)
                Console.WriteLine("Validated.")
            Catch e As ArgumentException
                Console.WriteLine("Failed validation.  Message: {0}", e.Message.ToString())
            End Try
        End Sub
    End Module
End Namespace

설명

IntegerValidator 클래스 정수 특정 조건을 충족 하는지 확인 하는 데 사용 됩니다. 유효성 검사에 대 한 조건을 설정의 인스턴스는 IntegerValidator 클래스가 만들어집니다. IntegerValidator 두 개의 매개 변수를 사용 하 여 생성자 따르는지 확인할 정수 최소값 및 최대값입니다. IntegerValidator 의 최소값 및 최대값을 확인 하는 세 개의 매개 변수를 사용 하 여 생성자 Int32 유효성을 검사 하려면 해당 값이 지정된 된 범위 내에서 뿐만 아니라 값입니다. IntegerValidator 4 개의 매개 변수를 사용 하 여 생성자를 이전 세 개의 매개 변수를 확인 확인 여부는 Int32 값은 특정 해상도 같습니다.

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

생성자

IntegerValidator(Int32, Int32)

IntegerValidator 클래스의 새 인스턴스를 초기화합니다.

IntegerValidator(Int32, Int32, Boolean)

IntegerValidator 클래스의 새 인스턴스를 초기화합니다.

IntegerValidator(Int32, Int32, Boolean, Int32)

IntegerValidator 클래스의 새 인스턴스를 초기화합니다.

메서드

CanValidate(Type)

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

Equals(Object)

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

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

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

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

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

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

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

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

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

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

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

적용 대상

추가 정보