共用方式為


StringValidatorAttribute.ValidatorInstance 屬性

定義

取得 StringValidator 類別的執行個體。

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

屬性值

StringValidator 驗證程式執行個體中目前的 ConfigurationValidatorBase 設定。

範例

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


            ConfigurationValidatorBase valBase;
            StringValidatorAttribute strValAttr =
            new StringValidatorAttribute();

            long badValue = 10;
            string goodValue = "10";

            try
            {
                valBase = strValAttr.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 strValAttr As New StringValidatorAttribute()

        Dim badValue As Long = 10
        Dim goodValue As String = "10"

        Try
            valBase = strValAttr.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使用 屬性來執行字串驗證。

適用於

另請參閱