using System; using System.Collections.Generic; using DPumpHydr.WinFrmUI.WenSkin.Json.Linq; using DPumpHydr.WinFrmUI.WenSkin.Json.Utilities; namespace DPumpHydr.WinFrmUI.WenSkin.Json.Schema { /// /// /// Contains the JSON schema extension methods. /// /// /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. /// /// [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] public static class Extensions { /// /// /// Determines whether the is valid. /// /// /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. /// /// /// The source to test. /// The schema to test with. /// /// true if the specified is valid; otherwise, false. /// [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] public static bool IsValid(this JToken source, JsonSchema schema) { bool valid = true; source.Validate(schema, delegate { valid = false; }); return valid; } /// /// /// Determines whether the is valid. /// /// /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. /// /// /// The source to test. /// The schema to test with. /// When this method returns, contains any error messages generated while validating. /// /// true if the specified is valid; otherwise, false. /// [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] public static bool IsValid(this JToken source, JsonSchema schema, out IList errorMessages) { IList errors = new List(); source.Validate(schema, delegate(object sender, ValidationEventArgs args) { errors.Add(args.Message); }); errorMessages = errors; return errorMessages.Count == 0; } /// /// /// Validates the specified . /// /// /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. /// /// /// The source to test. /// The schema to test with. [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] public static void Validate(this JToken source, JsonSchema schema) { source.Validate(schema, null); } /// /// /// Validates the specified . /// /// /// JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details. /// /// /// The source to test. /// The schema to test with. /// The validation event handler. [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler) { ValidationUtils.ArgumentNotNull(source, "source"); ValidationUtils.ArgumentNotNull(schema, "schema"); using JsonValidatingReader jsonValidatingReader = new JsonValidatingReader(source.CreateReader()); jsonValidatingReader.Schema = schema; if (validationEventHandler != null) { jsonValidatingReader.ValidationEventHandler += validationEventHandler; } while (jsonValidatingReader.Read()) { } } } }