-Formatting

-Build
This commit is contained in:
James Newton-King
2015-12-04 23:54:38 +13:00
parent c96779dc10
commit eb0cbd6a75
334 changed files with 3952 additions and 514 deletions
@@ -36,13 +36,15 @@ using Test = Xunit.FactAttribute;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
#else
using NUnit.Framework;
#endif
#if !(DNXCORE50 || NET20)
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
{
#region Types
#region Types
public class XmlJsonReader : JsonReader
{
private readonly Stack<JTokenType> _stateStack;
@@ -65,7 +67,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override bool Read()
{
if (HandleValueType())
{
return true;
}
while (_reader.Read())
{
@@ -74,7 +78,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
case XmlNodeType.Element:
string typeName = _reader.GetAttribute("type");
if (typeName == null)
{
throw new Exception("No type specified.");
}
_valueType = (JTokenType)Enum.Parse(typeof(JTokenType), typeName, true);
@@ -100,25 +106,33 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
SetToken(JsonToken.EndObject);
_stateStack.Pop();
if (PeekState() == JTokenType.Property)
{
_stateStack.Pop();
}
return true;
case JTokenType.Array:
SetToken(JsonToken.EndArray);
_stateStack.Pop();
if (PeekState() == JTokenType.Property)
{
_stateStack.Pop();
}
return true;
case JTokenType.Constructor:
SetToken(JsonToken.EndConstructor);
_stateStack.Pop();
if (PeekState() == JTokenType.Property)
{
_stateStack.Pop();
}
return true;
}
_stateStack.Pop();
if (PeekState() == JTokenType.Property)
{
_stateStack.Pop();
}
break;
case XmlNodeType.Text:
@@ -168,7 +182,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
_valueType = null;
if (PeekState() == JTokenType.Property)
{
_stateStack.Pop();
}
return true;
case JTokenType.Object:
SetToken(JsonToken.StartObject);
@@ -183,7 +199,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
case JTokenType.Constructor:
string constructorName = _reader.GetAttribute("name");
if (constructorName == null)
{
throw new Exception("No constructor name specified.");
}
SetToken(JsonToken.StartConstructor, constructorName);
_stateStack.Push(JTokenType.Constructor);
@@ -196,7 +214,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override int? ReadAsInt32()
{
if (!Read())
{
return null;
}
return (Value != null) ? (int?)Convert.ToInt32(Value) : null;
}
@@ -204,7 +224,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override string ReadAsString()
{
if (!Read())
{
return null;
}
return (string)Value;
}
@@ -212,7 +234,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override byte[] ReadAsBytes()
{
if (!Read())
{
return null;
}
return (byte[])Value;
}
@@ -220,7 +244,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override decimal? ReadAsDecimal()
{
if (!Read())
{
return null;
}
return (Value != null) ? (decimal?)Convert.ToDecimal(Value) : null;
}
@@ -228,7 +254,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override DateTime? ReadAsDateTime()
{
if (!Read())
{
return null;
}
return (Value != null) ? (DateTime?)Convert.ToDateTime(Value) : null;
}
@@ -236,12 +264,14 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
public override DateTimeOffset? ReadAsDateTimeOffset()
{
if (!Read())
{
return null;
}
return (Value != null) ? (DateTimeOffset?)Convert.ToDateTime(Value) : null;
}
}
#endregion
#endregion
[TestFixture]
public class CustomJsonReader : TestFixtureBase
@@ -249,7 +279,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
[Test]
public void Example()
{
#region Usage
#region Usage
string xml = @"<Root type=""Object"">
<Null type=""Null"" />
<String type=""String"">This is a string!</String>
@@ -308,7 +338,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
// "Constructor": new Date(2000, 12, 30)
//}
}
#endregion
#endregion
using (XmlReader xmlReader = XmlReader.Create(new StringReader(xml), new XmlReaderSettings { IgnoreWhitespace = true }))
using (XmlJsonReader reader = new XmlJsonReader(xmlReader))