public ValidationRule(Expression <Func <T, TResult> > exp, ValidationType type) { Expression = exp; if (type == ValidationType.Expand) { ValidatorHelpers.CheckExpressionIsProperty(exp); } ValidationType = type; }
private void AddRule <TResult>(string key, IValidationRule rule) { ValidatorHelpers.CheckTypeValid(typeof(TResult), rule.ValidationType, key); if (!Regex.IsMatch(key, @"^[a-zA-Z0-9_]+$")) { throw new InvalidValidationBuilderException("Key must only contain numbers, letters and underscores."); } if (!_validationRules.ContainsKey(key)) { _validationRules.Add(key, new ValidationRules(rule)); } else { _validationRules[key].AddRule(rule); } }
protected void CanExpand <TResult>(Expression <Func <T, TResult> > exp) where TResult : class { AddRule <TResult>(ValidatorHelpers.GetExpandString(exp.ToString()), new ValidationRule <T, TResult>(exp, ValidationType.Expand)); }