public void ValidateCurrentToken(JsonToken token, object value, int depth) { if (_scopes.Count == 0) { if (Schema == null) { throw new JSchemaException("No schema has been set for the validator."); } LicenseHelpers.IncrementAndCheckValidationCount(); SchemaScope.CreateTokenScope(token, Schema, _context, null, depth); } TokenWriter?.WriteToken(token, value); for (int i = _scopes.Count - 1; i >= 0; i--) { Scope scope = _scopes[i]; if (!scope.Complete) { scope.EvaluateToken(token, value, depth); } else { _scopes.RemoveAt(i); _scopesCache.Add(scope); } } if (TokenWriter != null && TokenWriter.Top == 0) { TokenWriter = null; } }
public void ValidateCurrentToken(JsonToken token, object?value, int depth) { if (depth == 0) { // Handle validating multiple content RemoveCompletedScopes(); } if (_scopes.Count == 0) { if (Schema == null) { throw new JSchemaException("No schema has been set for the validator."); } if (!_hasValidatedLicense) { LicenseHelpers.IncrementAndCheckValidationCount(); _hasValidatedLicense = true; } SchemaScope.CreateTokenScope(token, Schema, _context, null, depth); } if (TokenWriter != null) { // JTokenReader can return JsonToken.String with a null value which WriteToken doesn't like. // Hacky - change token to JsonToken.Null. Can be removed when fixed Newtonsoft.Json is public. JsonToken fixedToken = (token == JsonToken.String && value == null) ? JsonToken.Null : token; TokenWriter.WriteToken(fixedToken, value); } for (int i = _scopes.Count - 1; i >= 0; i--) { Scope scope = _scopes[i]; if (scope.Complete != CompleteState.Completed) { scope.EvaluateToken(token, value, depth); } else { _scopes.RemoveAt(i); _scopesCache.Add(scope); } } if (TokenWriter != null && (TokenWriter.WriteState == WriteState.Start || TokenWriter.WriteState == WriteState.Closed)) { TokenWriter = null; } }
protected void CreateScopesAndEvaluateToken(JsonToken token, object value, int depth, JSchema schema) { int startCount = Context.Scopes.Count; CreateTokenScope(token, schema, Context, this, depth); int start = Context.Scopes.Count - 1; int end = startCount; for (int i = start; i >= end; i--) { Scope newScope = Context.Scopes[i]; newScope.EvaluateToken(token, value, depth); } }
protected SchemaScope CreateScopesAndEvaluateToken(JsonToken token, object?value, int depth, JSchema schema, SchemaScope?parent, ContextBase context) { int startCount = Context.Scopes.Count; SchemaScope createdScope = CreateTokenScope(token, schema, context, parent, depth); int start = Context.Scopes.Count - 1; int end = startCount; for (int i = start; i >= end; i--) { Scope newScope = Context.Scopes[i]; newScope.EvaluateToken(token, value, depth); } return(createdScope); }
public void ValidateCurrentToken(JsonToken token, object value, int depth) { if (depth == 0) { // Handle validating multiple content RemoveCompletedScopes(); } if (_scopes.Count == 0) { if (Schema == null) { throw new JSchemaException("No schema has been set for the validator."); } if (!_hasValidatedLicense) { LicenseHelpers.IncrementAndCheckValidationCount(); _hasValidatedLicense = true; } SchemaScope.CreateTokenScope(token, Schema, _context, null, depth); } TokenWriter?.WriteToken(token, value); for (int i = _scopes.Count - 1; i >= 0; i--) { Scope scope = _scopes[i]; if (!scope.Complete) { scope.EvaluateToken(token, value, depth); } else { _scopes.RemoveAt(i); _scopesCache.Add(scope); } } if (TokenWriter != null && (TokenWriter.WriteState == WriteState.Start || TokenWriter.WriteState == WriteState.Closed)) { TokenWriter = null; } }