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)); }
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; }
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); }
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);
internal override Result DoMatch(JToken token, IJsonValidationContext context) { return !Constraint.DoMatch(token, context); }
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())); }
public override bool Matches(JToken token, IJsonValidationContext context) => !Constraint.Matches(token, context);
public override Result Test(JObject entity, IJsonValidationContext context) { //TODO: Lazy return Rules.Aggregate((Result)null, (result, rule) => result & rule.Test(entity, context)); }
public override Result Test(JObject entity, IJsonValidationContext contenxt) { return new RuleResult(this, new FuncResult(func(entity), explain)); }
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); }
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; }
public override bool Matches(IJsonValidationContext context, JToken token) => func(context, token);
public override Result Test(JObject entity, IJsonValidationContext contenxt) { return new RuleResult(this, new AnyResult()); }
protected override bool Matches(string value, IJsonValidationContext context) { return(value.Length >= minLength && value.Length <= maxLength); }
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()); }
protected override bool Matches(T value, IJsonValidationContext context) => value.CompareTo(maxValue) < 1;
internal override JsonConstraintResult DoMatch(IJsonValidationContext context, JToken token) { return(Constraints.Aggregate((JsonConstraintResult)null, (a, b) => a & b.DoMatch(context, token))); }
internal virtual Result DoMatch(JToken token, IJsonValidationContext context) { return new ConstraintResult(this, token, Matches(token, context)); }
public abstract bool Matches(IJsonValidationContext context, JToken token);
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)); }
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); }
public override bool Matches(IJsonValidationContext context, JToken token) { return(token != null && token.Type != JTokenType.Null && token.Type != JTokenType.Undefined); }
protected virtual bool Matches(IJsonValidationContext context, TTokenType value) { return(Matches(context, value, false)); }
public DynamicContext(IJsonValidationContext context, JObject root) { this.InnerContext = context; this.root = root; this.contextType = context?.GetType(); }
protected virtual bool Matches(IJsonValidationContext context, TTokenType value, bool wasNull) { return(true); }
protected override bool Matches(IJsonValidationContext context, string value) { return(value.Length <= maxLength); }
public override bool Matches(JToken token, IJsonValidationContext context) { return token != null; }
public override Result DoMatch(JToken token, IJsonValidationContext context) => !Constraint.DoMatch(token, context);
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)); }
public override Result Test(JObject entity, IJsonValidationContext contenxt) { return !Rule.Test(entity, contenxt); }
public abstract bool Matches(JToken token, IJsonValidationContext context);
public override bool Matches(IJsonValidationContext context, JToken token) { return(token == null ? Matches(context, default(TTokenType), true) : Matches(context, token.ToObject <TTokenType>())); }
public override Result DoMatch(JToken token, IJsonValidationContext context) => Constraints.Select(c => c.DoMatch(token, context)).Aggregate((a, b) => a & b);
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)); }