Exemplo n.º 1
0
        /// <summary>
        /// Load a collection of validators to be applied to a given user input field
        /// </summary>
        /// <param name="validatorCollection">The validator collection</param>
        /// <param name="defaultProperties">The default property values</param>
        private void LoadIndividualValidatorCollection(XmlNode validatorCollection, StringDictionary[] defaultProperties)
        {
            // The list of validators to be applied to the given field
            ArrayList validatorList = new ArrayList();

            // Remember the control to validate
            string controlToValidate = GetAttribute(validatorCollection, "ControlToValidate");

            // Iterate through each validator in the collection
            foreach (XmlNode validatorNode in validatorCollection.ChildNodes)
            {
                // Only process XML elements and ignore comments, etc
                if (validatorNode is XmlElement)
                {
                    // Use a new string dictionary to hold the validator's properties and values
                    StringDictionary validatorProperties = new StringDictionary();

                    // Remember which control this validator should validate
                    validatorProperties["ControlToValidate"] = controlToValidate;

                    // Remember the type of validator
                    string typeofValidator = GetAttribute(validatorNode, "type");
                    validatorProperties["ValidatorType"] = typeofValidator;

                    // Add the ServerValidate event handler (only used on Custom validators)
                    validatorProperties["ServerValidate"] = GetAttribute(validatorNode, "ServerValidate");

                    // Assign the default property values common to all validators
                    AssignDefaultValues(validatorProperties, defaultProperties[(int)ValidatorTypes.Common]);

                    // Assign the default property values specific to this type of validator
                    ValidatorTypes validatorType = (ValidatorTypes)Enum.Parse(typeof(ValidatorTypes), typeofValidator);
                    AssignDefaultValues(validatorProperties, defaultProperties[(int)validatorType]);

                    // Iterate through each property node
                    foreach (XmlNode propertyNode in validatorNode.ChildNodes)
                    {
                        // Only process XML elements and ignore comments, etc
                        if (propertyNode is XmlElement)
                        {
                            // Add property names/values explicitly given for this validator
                            string propertyName  = GetAttribute(propertyNode, "name");
                            string propertyValue = GetAttribute(propertyNode, "value");
                            validatorProperties[propertyName] = propertyValue;
                        }
                    }

                    // Now we have the string dictionary, make any fieldname replacements that might have been specified
                    ReplaceFieldnamesWithValues(validatorProperties, validatorCollection);

                    // Finally, add the string dictionary containing the validator property values to the list of validators for this group
                    validatorList.Add(validatorProperties);
                }
            }

            // Save the array list of validators for this group
            string collectionName = GetAttribute(validatorCollection, "id");

            validatorCollections[collectionName] = validatorList;
        }
Exemplo n.º 2
0
 public ValidatorAttribute(ValidatorTypes type, string regEx)
 {
     validatorType     = type;
     regularExpression = regEx;
 }