locked
IgnoreNulls in validation Configuration file RRS feed

  • Question

  • User619554136 posted

    How to specify IgnoreNulls in validation Configuration file rather attribute for proerty?

    I could not see Add Validator -> IgnoreNulls in Configuration Editor.

    Thursday, April 7, 2011 4:59 AM

Answers

  • User619554136 posted

    After spending 2 hours finally I've resolved the issue.

    we would need to nest the other validators inside "Or Composite validators". Earlier I defined all three indivisually.

    Following thread helped me to resolve the issue. http://forums.asp.net/t/1437922.aspx/1

    Below is the full code

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <validation>
    <type name="ValidationTest.Data" defaultRuleset="" assemblyName="ConsoleApplication4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <ruleset name="RuleSet1">
    <properties>
    <property name="Amount">
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.OrCompositeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="Or Composite Validator">
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    negated="true" name="Not Null Validator" />
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    culture="en-US" lowerBound="1" lowerBoundType="Inclusive"
    upperBound="100" name="Range Validator"/>
    </validator>
    </property>
    </properties>
    </ruleset>
    </type>
    </validation>
    </configuration>
    using System;
    using Microsoft.Practices.EnterpriseLibrary.Validation;
    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

    namespace ValidationTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Validator<Data> customerValidator;

    ValidatorFactory valFactory = EnterpriseLibraryContainer.Current.GetInstance<ValidatorFactory>();
    customerValidator = valFactory.CreateValidator<Data>("RuleSet1");

    Data data = new Data
    {
    Amount = null
    };

    ValidationResults results = customerValidator.Validate(data);

    Console.WriteLine(results.IsValid);
    }
    }

    public class Data
    {
    public Decimal? Amount { get; set; }
    }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 7:54 AM

All replies

  • User619554136 posted

    Here It Amount should be accepted with 33.

    Could any one help me What's going wrong here? Amount should accept either Null or, between 1 to 100

    using System;
    using Microsoft.Practices.EnterpriseLibrary.Validation;
    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

    namespace ValidationTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Validator<Data> customerValidator;

    ValidatorFactory valFactory =
    EnterpriseLibraryContainer.Current.GetInstance<ValidatorFactory>();
    customerValidator = valFactory.CreateValidator<Data>("RuleSet1");

    Data data = new Data
    {
    Amount = 33
    };

    ValidationResults results = customerValidator.Validate(data);

    Console.WriteLine(" " + results.IsValid);
    }
    }

    public class Data
    {
    public Decimal? Amount { get; set; }
    }
    }
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <validation>
    <type name="ValidationTest.Data" defaultRuleset="" assemblyName="ConsoleApplication4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <ruleset name="RuleSet1">
    <properties>
    <property name="Amount">
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.OrCompositeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="Or Composite Validator" />
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    negated="true" name="Not Null Validator" />
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    culture="en-US" lowerBound="1" lowerBoundType="Inclusive"
    upperBound="100" name="Range Validator" />
    </property>
    </properties>
    </ruleset>
    </type>
    </validation>
    </configuration>
    Thursday, April 7, 2011 5:39 AM
  • User619554136 posted

    After spending 2 hours finally I've resolved the issue.

    we would need to nest the other validators inside "Or Composite validators". Earlier I defined all three indivisually.

    Following thread helped me to resolve the issue. http://forums.asp.net/t/1437922.aspx/1

    Below is the full code

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <validation>
    <type name="ValidationTest.Data" defaultRuleset="" assemblyName="ConsoleApplication4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
    <ruleset name="RuleSet1">
    <properties>
    <property name="Amount">
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.OrCompositeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    name="Or Composite Validator">
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    negated="true" name="Not Null Validator" />
    <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    culture="en-US" lowerBound="1" lowerBoundType="Inclusive"
    upperBound="100" name="Range Validator"/>
    </validator>
    </property>
    </properties>
    </ruleset>
    </type>
    </validation>
    </configuration>
    using System;
    using Microsoft.Practices.EnterpriseLibrary.Validation;
    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

    namespace ValidationTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Validator<Data> customerValidator;

    ValidatorFactory valFactory = EnterpriseLibraryContainer.Current.GetInstance<ValidatorFactory>();
    customerValidator = valFactory.CreateValidator<Data>("RuleSet1");

    Data data = new Data
    {
    Amount = null
    };

    ValidationResults results = customerValidator.Validate(data);

    Console.WriteLine(results.IsValid);
    }
    }

    public class Data
    {
    public Decimal? Amount { get; set; }
    }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 7:54 AM