LongValidator 類別

定義

提供 Int64 值的驗證。

public ref class LongValidator : System::Configuration::ConfigurationValidatorBase
public class LongValidator : System.Configuration.ConfigurationValidatorBase
type LongValidator = class
    inherit ConfigurationValidatorBase
Public Class LongValidator
Inherits ConfigurationValidatorBase
繼承

範例

下列程式碼範例示範如何使用 LongValidator 類型。

using System;
using System.Configuration;

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

      // Create Long and Validator.
      Int64 testLong =    17592186044416;
      Int64 minLongVal =  1099511627776;
      Int64 maxLongVal =  281474976710656;
      LongValidator myLongValidator = 
       new LongValidator(minLongVal, maxLongVal, false);

      // Determine if the object to validate can be validated.
      Console.WriteLine("CanValidate: {0}",
        myLongValidator.CanValidate(testLong.GetType()));

      try
      {
        // Attempt validation.
        myLongValidator.Validate(testLong);
        Console.WriteLine("Validated.");
      }
      catch (ArgumentException e)
      {
        // Validation failed.
        Console.WriteLine("Error: {0}", e.Message.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}
Imports System.Configuration

Namespace Microsoft.Samples.AspNet.Validators
  Class UsingLongValidator
    Public Shared Sub Main()

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

      ' Create Long and Validator.
      Dim testLong As Int64 = 17592186044416
      Dim minLongVal As Int64 = 1099511627776
      Dim maxLongVal As Int64 = 281474976710656
      Dim myLongValidator As LongValidator = _
       New LongValidator(minLongVal, maxLongVal, False)

      ' Determine if the object to validate can be validated.
      Console.WriteLine("CanValidate: {0}", _
        myLongValidator.CanValidate(testLong.GetType()))

      Try
        ' Attempt validation.
        myLongValidator.Validate(testLong)
        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

備註

LongValidator用來確保 long (64 位帶正負號的整數) 符合特定準則。 建立 類別的實例時,會建立驗證的 LongValidator 準則。 建 LongValidator(Int64, Int64) 構函式可確保所驗證的值同時 long 遵守最小和最大長度。 建 LongValidator(Int64, Int64, Boolean) 構函式會檢查最小值和最大值 Int64 ,以及驗證範圍是否為獨佔。 建 LongValidator(Int64, Int64, Boolean, Int64) 構函式會檢查前三個參數,並檢查值是否 Int64 等於特定的解析值。

方法 CanValidate 會判斷所驗證的物件類型是否符合預期的型別。 正在驗證的物件會當做 方法的參數 Validate 傳遞。

建構函式

LongValidator(Int64, Int64)

初始化 LongValidator 類別的新執行個體。

LongValidator(Int64, Int64, Boolean)

初始化 LongValidator 類別的新執行個體。

LongValidator(Int64, Int64, Boolean, Int64)

初始化 LongValidator 類別的新執行個體。

方法

CanValidate(Type)

判斷是否可以驗證物件的型別。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
Validate(Object)

判斷物件的值是否有效。

適用於

另請參閱