diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonReader.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonReader.cs index bb64b4ff..20023bb1 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonReader.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonReader.cs @@ -19,6 +19,7 @@ using NUnit.Framework; namespace Newtonsoft.Json.Tests.Documentation.Samples.Json { + #region Types public class XmlJsonReader : JsonReader { private readonly Stack _stateStack; @@ -217,11 +218,13 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json return (Value != null) ? (DateTimeOffset?)Convert.ToDateTime(Value) : null; } } + #endregion public class CustomJsonReader { public void Example() { + #region Usage string xml = @" This is a string! @@ -280,6 +283,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json // "Constructor": new Date(2000, 12, 30) //} } + #endregion using (XmlReader xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { IgnoreWhitespace = true })) using (XmlJsonReader reader = new XmlJsonReader(xmlReader)) diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonWriter.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonWriter.cs index b36cb37b..3b7bfe42 100644 --- a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonWriter.cs +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Json/CustomJsonWriter.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json.Linq; namespace Newtonsoft.Json.Tests.Documentation.Samples.Json { + #region Types public class XmlJsonWriter : JsonWriter { private readonly XmlWriter _writer; @@ -272,13 +273,50 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json } } } + #endregion public class CustomJsonWriter { public void Example() { + #region Usage + var user = new + { + Name = "James", + Age = 30, + Enabled = true, + Roles = new[] + { + "Publisher", + "Administrator" + } + }; + StringWriter sw = new StringWriter(); + using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { OmitXmlDeclaration = true })) + using (XmlJsonWriter writer = new XmlJsonWriter(xmlWriter)) + { + writer.Formatting = Formatting.Indented; + + JsonSerializer serializer = new JsonSerializer(); + serializer.Serialize(writer, user); + } + + Console.WriteLine(sw.ToString()); + // + // James + // 30 + // true + // + // Publisher + // Administrator + // + // + #endregion + + sw = new StringWriter(); + using (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings { OmitXmlDeclaration = true })) using (XmlJsonWriter writer = new XmlJsonWriter(xmlWriter)) {