Enterprise library Validation block and rulesets

Posted by user102533 on Stack Overflow See other posts from Stack Overflow or by user102533
Published on 2010-04-05T14:56:49Z Indexed on 2010/04/05 18:13 UTC
Read the original article Hit count: 338

I am using Rulesets on a type that looks like this:

public class Salary
{

   public decimal HourlyRate { get; set; }

   [ValidHours]  //Custom validator
   public int NumHours { get; set; }

   [VerifyValidState(Ruleset="State")]  //Custom validator with ruleset
   public string State { get; set; }
}

Due to business requirements, I'd need to first validate the ruleset "State" and then validate the entire business entity

public void Save()
{
   ValidationResults results = Validation.Validate(salary, "State");

   //Check for validity

   //Now run the validation for ALL rules including State ruleset
   ValidationResults results2 = Validation.Validate(salary); //Does not run the ruleset marked with "State"

}

How do I accomplish what I am trying to do?

© Stack Overflow or respective owner

Related posts about enterprise-library

Related posts about validation