コード例 #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;
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
 }
コード例 #7
0
 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);
 }
コード例 #10
0
 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
ファイル: AndJsonRule.cs プロジェクト: dotJEM/json-validation
 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());
 }
コード例 #15
0
 public override bool Matches(IJsonValidationContext context, JToken token)
 {
     return(true);
 }
コード例 #16
0
ファイル: Rule.cs プロジェクト: fossabot/json-validation
 public abstract Result Test(JObject entity, IJsonValidationContext contenxt);
コード例 #17
0
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(new FuncJsonRuleResult(func, func(entity)));
 }
コード例 #18
0
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(new AnyJsonRuleResult());
 }
コード例 #19
0
 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));
 }
コード例 #27
0
 public abstract bool Matches(IJsonValidationContext context, JToken token);
コード例 #28
0
 public override bool Matches(JToken token, IJsonValidationContext context)
 {
     throw new InvalidOperationException();
 }
コード例 #29
0
 internal virtual JsonConstraintResult DoMatch(IJsonValidationContext context, JToken token)
 {
     return(new BasicJsonConstraintResult(Matches(context, token), Describe(context, token), GetType()));
 }
コード例 #30
0
 public override JsonRuleResult Test(IJsonValidationContext contenxt, JObject entity)
 {
     return(!Rule.Test(contenxt, entity));
 }
コード例 #31
0
 public virtual JsonConstraintDescription Describe(IJsonValidationContext context, JToken token)
 {
     return(new JsonConstraintDescription(this, description.Format));
 }
コード例 #32
0
 protected override bool Matches(T value, IJsonValidationContext context)
 {
     return(value.CompareTo(minValue) > 0);
 }
コード例 #33
0
 public override JsonRuleResult Test(IJsonValidationContext context, JObject entity)
 {
     //TODO: Lazy
     return(Rules.Aggregate(new AndJsonRuleResult(), (result, rule) => result & rule.Test(context, entity)));
 }
コード例 #34
0
 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
ファイル: NotJsonRule.cs プロジェクト: dotJEM/json-validation
 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));
 }
コード例 #49
0
 protected override bool Matches(string value, IJsonValidationContext context)
 {
     return(comparer.Equals(value, this.value));
 }