Пример #1
0
 public Result Validate(JObject entity, IJsonValidationContext context)
 {
     Result gr = guard.Test(entity, context);
     return !gr.Value
         ? new FieldResult(this, gr, null)
         : new FieldResult(this, gr, rule.Test(entity, context));
 }
Пример #2
0
        public override bool Matches(JToken token, IJsonValidationContext context)
        {
            JArray arr = token as JArray;
            if (arr != null)
                return arr.Count <= maxLength;

            if (token.Type == JTokenType.String)
                return ((string)token).Length <= maxLength;

            return false;
        }
Пример #3
0
        public override bool Matches(JToken token, IJsonValidationContext context)
        {
            JArray arr = token as JArray;
            if (arr != null)
                return arr.Count >= minLength && arr.Count <= maxLength;

            if (token.Type != JTokenType.String)
                return false;

            string value = (string) token;
            return value.Length >= minLength && value.Length <= maxLength;
        }
        public override bool Matches(JToken token, IJsonValidationContext context)
        {
            //Note: If the token type matches we are happy regardless.
            if (token.Type == JTokenType.Boolean) return true;

            //Note: If the token type was not a match, and strict is enabled, return false.
            if (strict) return false;

            //Note: Only strings are allowed as an alternative. (for now, a integer could perhaps also make sense as 0 = false, 1 = true)
            if (token.Type != JTokenType.String) return false;

            bool boolean;
            return bool.TryParse((string)token, out boolean);
        }
        public override bool Matches(JToken token, IJsonValidationContext context)
        {
            //Note: If the token type matches we are happy regardless.
            if (token.Type == JTokenType.Float || token.Type == JTokenType.Integer) return true;

            //Note: If the token type was not a match, and strict is enabled, return false.
            if (strict) return false;

            //Note: Only strings are allowed as an alternative.
            if (token.Type != JTokenType.String) return false;

            double number;
            return double.TryParse((string)token, out number);
        }
Пример #6
0
 protected override bool Matches(T value, bool wasNull, IJsonValidationContext context)
 {
     return(values.Contains(value));
 }
 protected override bool Matches(IJsonValidationContext context, string value) => expression.IsMatch(value);
Пример #8
0
 internal override Result DoMatch(JToken token, IJsonValidationContext context)
 {
     return !Constraint.DoMatch(token, context);
 }
Пример #9
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     return(false);
 }
 public override JsonRuleResult Test(IJsonValidationContext context, JObject entity)
 {
     return(new AndJsonRuleResult(
                (from token in SelectTokens(entity)
                 select(JsonRuleResult) new BasicJsonRuleResult(Selector, token, constraint.DoMatch(context, token))).ToList()));
 }
Пример #11
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 => !Constraint.Matches(token, context);
Пример #12
0
 public override Result Test(JObject entity, IJsonValidationContext context)
 {
     //TODO: Lazy
     return Rules.Aggregate((Result)null, (result, rule) => result & rule.Test(entity, context));
 }
Пример #13
0
 public override Result Test(JObject entity, IJsonValidationContext contenxt)
 {
     return new RuleResult(this, new FuncResult(func(entity), explain));
 }
Пример #14
0
 public override Result Test(JObject entity, IJsonValidationContext context)
 {
     return new AndResult(
         (from token in Selector.SelectTokens(entity)
          select (Result)new EmbededValidatorResult(this, validator.Validate((JObject)token, context))).ToList());
 }
 public override bool Matches(IJsonValidationContext context, JToken token)
 {
     return(true);
 }
Пример #16
0
 public abstract Result Test(JObject entity, IJsonValidationContext contenxt);
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(new FuncJsonRuleResult(func, func(entity)));
 }
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(new AnyJsonRuleResult());
 }
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     return token.Type == JTokenType.Array;
 }
Пример #20
0
 public override bool Matches(IJsonValidationContext context, JToken token) => func(context, token);
Пример #21
0
 public override Result Test(JObject entity, IJsonValidationContext contenxt)
 {
     return new RuleResult(this, new AnyResult());
 }
Пример #22
0
 protected override bool Matches(string value, IJsonValidationContext context)
 {
     return(value.Length >= minLength && value.Length <= maxLength);
 }
Пример #23
0
 public override Result Test(JObject entity, IJsonValidationContext context)
 {
     return new AndResult(
         (from token in Selector.SelectTokens(entity)
          select (Result)new RuleResult(this, constraint.DoMatch(token, context))).ToList());
 }
Пример #24
0
 protected override bool Matches(T value, IJsonValidationContext context) => value.CompareTo(maxValue) < 1;
Пример #25
0
 internal override JsonConstraintResult DoMatch(IJsonValidationContext context, JToken token)
 {
     return(Constraints.Aggregate((JsonConstraintResult)null, (a, b) => a & b.DoMatch(context, token)));
 }
Пример #26
0
 internal virtual Result DoMatch(JToken token, IJsonValidationContext context)
 {
     return new ConstraintResult(this, token, Matches(token, context));
 }
 public abstract bool Matches(IJsonValidationContext context, JToken token);
Пример #28
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     throw new InvalidOperationException();
 }
 internal virtual JsonConstraintResult DoMatch(IJsonValidationContext context, JToken token)
 {
     return(new BasicJsonConstraintResult(Matches(context, token), Describe(context, token), GetType()));
 }
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(!Rule.Test(contenxt, entity));
 }
 public virtual JsonConstraintDescription Describe(IJsonValidationContext context, JToken token)
 {
     return(new JsonConstraintDescription(this, description.Format));
 }
 protected override bool Matches(T value, IJsonValidationContext context)
 {
     return(value.CompareTo(minValue) > 0);
 }
 public override JsonRuleResult Test(IJsonValidationContext context, JObject entity)
 {
     //TODO: Lazy
     return(Rules.Aggregate(new AndJsonRuleResult(), (result, rule) => result & rule.Test(context, entity)));
 }
 protected override bool Matches(IJsonValidationContext context, string value)
 {
     return(value.Equals(this.value, comparison));
 }
Пример #35
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     //TODO: Should null return true or falls, a string can be null after all.
     return(token != null && token.Type == JTokenType.String);
 }
Пример #36
0
 public override bool Matches(IJsonValidationContext context, JToken token)
 {
     return(token != null && token.Type != JTokenType.Null && token.Type != JTokenType.Undefined);
 }
Пример #37
0
 protected virtual bool Matches(IJsonValidationContext context, TTokenType value)
 {
     return(Matches(context, value, false));
 }
Пример #38
0
 public DynamicContext(IJsonValidationContext context, JObject root)
 {
     this.InnerContext = context;
     this.root         = root;
     this.contextType  = context?.GetType();
 }
Пример #39
0
 protected virtual bool Matches(IJsonValidationContext context, TTokenType value, bool wasNull)
 {
     return(true);
 }
Пример #40
0
 protected override bool Matches(IJsonValidationContext context, string value)
 {
     return(value.Length <= maxLength);
 }
Пример #41
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     return token != null;
 }
Пример #42
0
 public override Result DoMatch(JToken token, IJsonValidationContext context)
 => !Constraint.DoMatch(token, context);
Пример #43
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     //TODO: This is a bit heavy for simple values, it only makes sense for objects and arrays.
     return JToken.DeepEquals(token, JToken.FromObject(value));
 }
Пример #44
0
 public override Result Test(JObject entity, IJsonValidationContext contenxt)
 {
     return !Rule.Test(entity, contenxt);
 }
Пример #45
0
 public abstract bool Matches(JToken token, IJsonValidationContext context);
Пример #46
0
 public override bool Matches(IJsonValidationContext context, JToken token)
 {
     return(token == null
         ? Matches(context, default(TTokenType), true)
         : Matches(context, token.ToObject <TTokenType>()));
 }
Пример #47
0
 public override Result DoMatch(JToken token, IJsonValidationContext context)
 => Constraints.Select(c => c.DoMatch(token, context)).Aggregate((a, b) => a & b);
Пример #48
0
 internal override Result DoMatch(JToken token, IJsonValidationContext context)
 {
     return Constraints.Aggregate((Result)null, (a, b) => a | b.DoMatch(token, context));
 }
 protected override bool Matches(string value, IJsonValidationContext context)
 {
     return(comparer.Equals(value, this.value));
 }