Partager via


RegexStringValidatorAttribute.ValidatorInstance Propriété

Définition

Obtient une instance de la classe 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

Valeur de propriété

Instance du validateur ConfigurationValidatorBase.

Exemples

L'exemple suivant illustre l'utilisation de la méthode 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 '

Remarques

Vous utilisez la propriété pour effectuer la ValidatorInstance validation de chaîne en appelant sa Validate méthode.

S’applique à

Voir aussi