private void AddValidationRule(string propertyName, IViewModelValidationRule rule) { if (ValidationRules.ContainsKey(propertyName)) { ValidationRules[propertyName].Add(rule); } else { ValidationRules.Add(propertyName, new List <IViewModelValidationRule> { rule }); } }
protected void AddValidationRule <TResult>(Expression <Func <TResult> > propertyExpression, IViewModelValidationRule rule) { if (propertyExpression.Body.NodeType == ExpressionType.MemberAccess) { var memberExpr = propertyExpression.Body as MemberExpression; if (memberExpr != null) { string propertyName = memberExpr.Member.Name; AddValidationRule(propertyName, rule); } else { throw new Exception("Property not found"); } } }