public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType != typeof(PatchDocument))
            {
                throw new ArgumentException("Object must be of type PatchDocument", nameof(objectType));
            }

            try {
                if (reader.TokenType == JsonToken.Null)
                {
                    return(null);
                }

                var patch = JArray.Load(reader);
                return(PatchDocument.Parse(patch.ToString()));
            } catch (Exception ex) {
                throw new ArgumentException("Invalid patch document: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        public static PatchDocument Load(JArray document)
        {
            var root = new PatchDocument();

            if (document == null)
            {
                return(root);
            }

            foreach (var jOperation in document.Children())
            {
                var jObject = jOperation as JObject;
                if (jObject != null)
                {
                    var op = Operation.Build(jObject);
                    root.AddOperation(op);
                }
            }

            return(root);
        }