Foundatio.Repositories.JsonPatch.PatchDocument.Parse C# (CSharp) Method

Parse() public static method

public static Parse ( string jsondocument ) : PatchDocument
jsondocument string
return PatchDocument
        public static PatchDocument Parse(string jsondocument) {
            var root = JToken.Parse(jsondocument) as JArray;

            return Load(root);
        }

Usage Example

        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);
            }
        }