示例#1
0
 public ValidationRule(Expression <Func <T, TResult> > exp, ValidationType type)
 {
     Expression = exp;
     if (type == ValidationType.Expand)
     {
         ValidatorHelpers.CheckExpressionIsProperty(exp);
     }
     ValidationType = type;
 }
示例#2
0
        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);
            }
        }
示例#3
0
 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));
 }