IntegerValidator クラス
アセンブリ: System.Configuration (system.configuration.dll 内)


IntegerValidator は、整数が特定の基準を満たしていることを確認するために使用されます。検証の基準は、IntegerValidator がインスタンス化されたときに設定されます。IntegerValidator 用に、4 つのコンストラクタ オーバーロードがあります。パラメータが 1 つ指定された IntegerValidator コンストラクタは、検証される整数に設定できる最小長を確認します。パラメータが 2 つ指定された IntegerValidator コンストラクタは、検証される整数が、最小長と最大長の両方に従っていることを確認します。パラメータが 3 つ指定された IntegerValidator コンストラクタは、Int32 の最小値と最大値の両方を確認し、検証範囲が排他的かどうかも確認します。パラメータが 4 つ指定された IntegerValidator コンストラクタは、前述の 3 つのパラメータについて確認し、さらに Int32 が特定の解決と同じかどうかも確認します。
CanValidate メソッドは、検証されるオブジェクト型が、正しい型に一致しているかどうかを確認します。検証されるオブジェクトは、Validate メソッドのパラメータとして渡されます。

IntegerValidator 型を使用する方法を次のコード例に示します。
Imports System Imports System.Configuration Namespace Microsoft.Samples.AspNet.Validators Class UsingIntegerValidator Public Shared Sub Main() ' Display title. Console.WriteLine("ASP.NET Validators") Console.WriteLine() ' Create Integer and Validator. Dim testInt As Int32 = 5 Dim minIntVal As Int32 = 1 Dim maxIntVal As Int32 = 10 Dim myIntegerValidator As IntegerValidator = _ New IntegerValidator(minIntVal, maxIntVal, False) ' Determine if the object to validate can be validated. Console.WriteLine("CanValidate: {0}", _ myIntegerValidator.CanValidate(testInt.GetType())) Try ' Attempt validation. myIntegerValidator.Validate(testInt) 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
using System; using System.Configuration; namespace Microsoft.Samples.AspNet.Validators { class UsingIntergerValidator { static void Main(string[] args) { // Display title. Console.WriteLine("ASP.NET Validators"); Console.WriteLine(); // Create Integer and Validator. int testInt = 5; int minIntVal = 1; int maxIntVal = 10; IntegerValidator myIntegerValidator = new IntegerValidator(minIntVal, maxIntVal, false); // Determine if the object to validate can be validated. Console.WriteLine("CanValidate: {0}", myIntegerValidator.CanValidate(testInt.GetType())); try { // Attempt validation. myIntegerValidator.Validate(testInt); Console.WriteLine("Validated."); } catch (ArgumentException e) { // Validation failed. Console.WriteLine("Error: {0}", e.Message.ToString()); } // Display and wait Console.ReadLine(); } } }

System.Configuration.ConfigurationValidatorBase
System.Configuration.IntegerValidator


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- IntegerValidator クラスのページへのリンク