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

ToStream() public method

public ToStream ( ) : MemoryStream
return System.IO.MemoryStream
        public MemoryStream ToStream() {
            var stream = new MemoryStream();
            CopyToStream(stream, Formatting.Indented);
            stream.Flush();
            stream.Position = 0;
            return stream;
        }

Usage Example

        public void SerializePatchDocument() {
            var patchDoc = new PatchDocument(
                new TestOperation { Path = "/a/b/c", Value = new JValue("foo") },
                new RemoveOperation { Path = "/a/b/c" },
                new AddOperation { Path = "/a/b/c", Value = new JArray(new JValue("foo"), new JValue("bar")) },
                new ReplaceOperation { Path = "/a/b/c", Value = new JValue(42) },
                new MoveOperation { FromPath = "/a/b/c", Path = "/a/b/d" },
                new CopyOperation { FromPath = "/a/b/d", Path = "/a/b/e" });

            var outputstream = patchDoc.ToStream();
            var output = new StreamReader(outputstream).ReadToEnd();

            var jOutput = JToken.Parse(output);

            Assert.Equal(@"[{""op"":""test"",""path"":""/a/b/c"",""value"":""foo""},{""op"":""remove"",""path"":""/a/b/c""},{""op"":""add"",""path"":""/a/b/c"",""value"":[""foo"",""bar""]},{""op"":""replace"",""path"":""/a/b/c"",""value"":42},{""op"":""move"",""path"":""/a/b/d"",""from"":""/a/b/c""},{""op"":""copy"",""path"":""/a/b/e"",""from"":""/a/b/d""}]",
                jOutput.ToString(Formatting.None));
        }