示例#1
0
 public PathValidation(PathValueIndexer <TSource> indexer, ValidationRuleFactory <TSource> factory)
 {
     Id      = Guid.NewGuid();
     Indexer = indexer;
     Path    = indexer?.PathName;
     Factory = factory;
 }
示例#2
0
        public static PathValidation <JObject, TProperty> JObjectRuleFor <TProperty>(this ValidationRuleFactory <JObject> factory,
                                                                                     JObjectFieldsBuilder <TProperty> fields)
        {
            var path = new JObjectPath(fields);

            return(factory.RuleForIf <TProperty>(path, null));
        }
示例#3
0
        public ValidationRuleFactory <TSource> Clone(TSource newOriginalValue)
        {
            var result = new ValidationRuleFactory <TSource>(Repository, newOriginalValue);

            CopyTo(result);

            return(result);
        }
示例#4
0
        public ValidationRuleFactory <T> Create <T>(T value, Action <ValidationRuleFactory <T> > init = null)
        {
            var result = new ValidationRuleFactory <T>(this, value);

            init?.Invoke(result);

            return(result);
        }
示例#5
0
        public static PathValidation <TSource, TResult> Complex <TSource, TResult>(this PathValidation <TSource, TResult> validation,
                                                                                   ValidationRuleFactory <TResult> rules)
        {
            validation.AddValidator(new ComplexRule <TResult>()
            {
                Factory = rules
            });

            return(validation);
        }
示例#6
0
        private void CopyTo(ValidationRuleFactory <TSource> accum)
        {
            foreach (var t in m_validators)
            {
                accum.m_validators.Add(t.Clone());
            }

            foreach (var t in m_conditions)
            {
                accum.m_conditions[t.Key] = t.Value;
            }
        }
示例#7
0
        public static PathValidation <TSource, TProperty> RuleFor <TSource, TProperty>(this ValidationRuleFactory <TSource> factory,
                                                                                       Expression <Func <TSource, TProperty> > expression)
        {
            var path = PathValueIndexer <TSource> .m_factory.GetPathItems(expression);

            return(factory.RuleForIf <TProperty>(path, null));
        }
示例#8
0
        public static PathValidation <JObject, TProperty> JObjectRuleForIf <TProperty>(this ValidationRuleFactory <JObject> factory,
                                                                                       Func <JObjectFieldsBuilder, JObjectFieldsBuilder <TProperty> > fields,
                                                                                       Func <JObject, bool> condition)
        {
            var path = new JObjectPath(fields(new JObjectFieldsBuilder()));

            return(factory.RuleForIf <TProperty>(path, condition));
        }
示例#9
0
 public ValidationRuleFactory <TSource> Append(ValidationRuleFactory <TSource> otherFactory)
 {
     otherFactory.CopyTo(this);
     return(this);
 }