How to not specify ruleset name when reading from config file?

Posted by user102533 on Stack Overflow See other posts from Stack Overflow or by user102533
Published on 2010-04-05T18:41:58Z Indexed on 2010/04/05 18:43 UTC
Read the original article Hit count: 298

When I read rules from a configuration file, I do something like this:

IConfigurationSource configurationSource = new FileConfigurationSource("myvalidation.config");
var validator = ValidationFactory.CreateValidator<Salary>(configurationSource);

The config file looks like this:

<ruleset name="Default">
  <properties>
    <property name="Address">
       <validator lowerBound="10" lowerBoundType="Inclusive" upperBound="15"
            upperBoundType="Inclusive" negated="false" messageTemplate=""
            messageTemplateResourceName="" messageTemplateResourceType=""
            tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"
name="String Length Validator" />
     </property>
  </properties>
</ruleset>

My question is - is there a way to not specify the ruleset name? It's not required for me to specify a ruleset name if I am using the attribute approach and I can validate using:

ValidationResults results = Validation.Validate(salary);

Now when reading from config files, I have to specify the ruleset name. There is no overload of the CreateValidator method that accepts the configuration source without specifying the ruleset name. Also, the xml in the config file requires a name attribute for ruleset

© Stack Overflow or respective owner

Related posts about validation

Related posts about enterprise-library