Extracting Validation Logic to Model

Mar 25, 2014 at 9:17 PM
Edited Mar 25, 2014 at 9:20 PM
Just as an example I'm trying to figure out a way to extract just the validation logic into my model project. This model project does not have a dll reference that would allow me to return a RuleResult in a function nor do i think my model project should so I'm trying to find the best alternative solution and I was hoping for some opinions from other people.
     public int Age
          get { return userModel.Age; }
              userModel.Age = value;

     Validator.AddRule(() => Age, 
         () => 
               if (Age < 1)
                     return RuleResult.Invalid("Age Cannot be less than 1");
               else if (Age > 100)
                     return RuleResult.Invalid("Yeah sure!");

               retirm RuleResult.Valid();
So I would like to centralize/extract those if statements possibly into the UserModel entity or maybe a service layer. Keep in mind I'm hoping for something that isn't clunky for I have many many properties that have unique validation logic.