共用方式為


RegexStringValidatorAttribute.ValidatorInstance 屬性

定義

取得 RegexStringValidator 類別的執行個體。

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;

            RegexStringValidatorAttribute rstrValAttr =
            new RegexStringValidatorAttribute(@"\w+\S*");

            // Get the regular expression string.
            string regex = rstrValAttr.Regex;
            Console.WriteLine("Regular expression: {0}", regex);


            string badValue = "&%$bbb";
            string goodValue = "filename.txt";

            try
            {
                valBase = rstrValAttr.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 rstrValAttr As _
        New RegexStringValidatorAttribute("\w+\S*")

        ' Get the regular expression string.
        Dim regex As String = _
        rstrValAttr.Regex
        Console.WriteLine( _
        "Regular expression: {0}", regex)

        Dim badValue As _
        String = "&%$bbb"
        Dim goodValue As _
        String = "filename.txt"

        Try
            valBase = rstrValAttr.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 '

備註

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

適用於

另請參閱