Пример #1
0
        JsonValidationError ValidateWithRule(JsonValidationRule rule, JsonObject obj)
        {
            var foundValue = obj.GetValueFromPath(rule.Path);

            JsonValidationErrorKind validationError;

            if (foundValue == null)
            {
                validationError = JsonValidationErrorKind.Missing;
            }
            else
            {
                if (foundValue.ValueType == JsonValueType.Null)
                {
                    validationError = JsonValidationErrorKind.NullValue;
                }
                else if (foundValue.ValueType != rule.ExpectedType)
                {
                    validationError = JsonValidationErrorKind.IncorrectType;
                }
                else
                {
                    validationError = JsonValidationErrorKind.None;
                }
            }

            if (validationError == JsonValidationErrorKind.None)
            {
                return(null);
            }
            else
            {
                return(new JsonValidationError(rule, validationError));
            }
        }
Пример #2
0
 public void AddRule(JsonValidationRule rule)
 {
     _rules.Add(rule);
 }