/// <inheritdoc /> public DocumentValidatorResult Validate( ISchema schema, DocumentNode document, IEnumerable <KeyValuePair <string, object?> >?contextData) { if (schema is null) { throw new ArgumentNullException(nameof(schema)); } if (document is null) { throw new ArgumentNullException(nameof(document)); } DocumentValidatorContext context = _contextPool.Get(); try { PrepareContext(schema, document, context, contextData); for (var i = 0; i < _rules.Length; i++) { _rules[i].Validate(context, document); } return(context.Errors.Count > 0 ? new DocumentValidatorResult(context.Errors) : DocumentValidatorResult.Ok); } finally { _contextPool.Return(context); } }
public DocumentValidatorResult Validate(ISchema schema, DocumentNode document) { if (schema is null) { throw new ArgumentNullException(nameof(schema)); } if (document is null) { throw new ArgumentNullException(nameof(document)); } DocumentValidatorContext context = _contextPool.Get(); try { PrepareContext(schema, document, context); for (int i = 0; i < _rules.Length; i++) { _rules[i].Validate(context, document); } if (context.Errors.Count > 0) { return(new DocumentValidatorResult(context.Errors)); } return(DocumentValidatorResult.OK); } finally { _contextPool.Return(context); } }
/// <inheritdoc /> public DocumentValidatorResult Validate( ISchema schema, DocumentNode document, IDictionary <string, object?> contextData, bool onlyNonCacheable = false) { if (schema is null) { throw new ArgumentNullException(nameof(schema)); } if (document is null) { throw new ArgumentNullException(nameof(document)); } if (onlyNonCacheable && _nonCacheableRules.Length == 0) { return(DocumentValidatorResult.Ok); } DocumentValidatorContext context = _contextPool.Get(); IDocumentValidatorRule[] rules = onlyNonCacheable ? _nonCacheableRules : _allRules; try { PrepareContext(schema, document, context, contextData); foreach (var rule in rules) { rule.Validate(context, document); } return(context.Errors.Count > 0 ? new DocumentValidatorResult(context.Errors) : DocumentValidatorResult.Ok); } finally { _contextPool.Return(context); } }