public bool Check <T>(string propertyName, T obj, bool collectErrors = false) { if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentException("Argument \"propertyName\" cannot be NULL"); } if (!RuleSets.ContainsKey(propertyName)) { return(true); } if (collectErrors == true && Errors.ContainsKey(propertyName)) { Errors.Remove(propertyName); } IDelegateRuleSet <T> ruleSet = (IDelegateRuleSet <T>)RuleSets[propertyName]; if (!ruleSet.Check(obj)) { if (collectErrors == true) { Errors.Add(propertyName, ruleSet.Errors); RaiseErrorsChanged(propertyName); } return(false); } return(true); }
public void AddRuleSet <P>(string propertyName, IDelegateRuleSet <P> ruleSet) { if (string.IsNullOrEmpty(propertyName)) { throw new Exception("Property name cannot be empty string or null"); } if (RuleSets.ContainsKey(propertyName)) { throw new Exception(string.Format("RuleSet already exists for property \"{0}\"", propertyName)); } RuleSets.Add(propertyName, ruleSet); }