共用方式為


IntegerValidatorAttribute.ValidatorInstance 屬性

定義

取得 IntegerValidator 類別的執行個體。

public:
 virtual property System::Configuration::ConfigurationValidatorBase ^ ValidatorInstance { System::Configuration::ConfigurationValidatorBase ^ get(); };
public override System.Configuration.ConfigurationValidatorBase ValidatorInstance { get; }
member this.ValidatorInstance : System.Configuration.ConfigurationValidatorBase
Public Overrides ReadOnly Property ValidatorInstance As ConfigurationValidatorBase

屬性值

ConfigurationValidatorBase 驗證程式執行個體。

範例

下列範例將示範如何使用 ValidatorInstance 屬性。


            ConfigurationValidatorBase valBase;
            IntegerValidatorAttribute intValAttr;
            intValAttr = new IntegerValidatorAttribute();

            long badValue = 10;
            int goodValue = 10;

            try
            {
                valBase = intValAttr.ValidatorInstance;
                valBase.Validate(goodValue);
                // valBase.Validate(badValue);
            }
            catch (ArgumentException e)
            {
                // Display error message.
                string msg = e.ToString();
#if DEBUG
                Console.WriteLine(msg);
#endif
            }
        Dim valBase As ConfigurationValidatorBase
        Dim intValAttr As IntegerValidatorAttribute
        intValAttr = New IntegerValidatorAttribute()

        Dim badValue As Long = 10
        Dim goodValue As Integer = 10

        Try
            valBase = intValAttr.ValidatorInstance
            valBase.Validate(goodValue)
            ' valBase.Validate(badValue);
        Catch e As ArgumentException
            ' Display error message.
            Dim msg As String = e.ToString()
#If DEBUG Then
            Console.WriteLine(msg)
#End If
        End Try '

備註

您可以藉由呼叫 其 Validate 方法,ValidatorInstance使用 屬性來執行字串驗證。

適用於