-Rename JsonTokenReader, JsonTokenWriter, JsonTokenType to JTokenReader, JTokenWriter, JTokenType

This commit is contained in:
JamesNK
2009-04-10 04:45:58 +00:00
parent 3630a43f11
commit ed53b0c9ad
29 changed files with 203 additions and 203 deletions
+3 -3
View File
@@ -59,8 +59,8 @@
</div></div> </div></div>
<h3>JsonTokenReader and JsonTokenWriter</h3> <h3>JTokenReader and JTokenWriter</h3>
<p><a href="./html/T_Newtonsoft_Json_JsonTokenReader.htm">JsonTokenReader</a> and <a href="./html/T_Newtonsoft_Json_JsonTokenWriter.htm">JsonTokenWriter</a> read and write LINQ to JSON objects. They are located in the <a href="./html/N_Newtonsoft_Json_Linq.htm">Newtonsoft.Json.Linq</a> namespace. These objects allow you to use LINQ to JSON objects with objects that read and write JSON such as the JsonSerializer. For example you can deserialize from a LINQ to JSON object into a regular .NET object and vice versa.</p> <p><a href="./html/T_Newtonsoft_Json_JTokenReader.htm">JTokenReader</a> and <a href="./html/T_Newtonsoft_Json_JTokenWriter.htm">JTokenWriter</a> read and write LINQ to JSON objects. They are located in the <a href="./html/N_Newtonsoft_Json_Linq.htm">Newtonsoft.Json.Linq</a> namespace. These objects allow you to use LINQ to JSON objects with objects that read and write JSON such as the JsonSerializer. For example you can deserialize from a LINQ to JSON object into a regular .NET object and vice versa.</p>
<div class="overflowpanel"> <div class="code"> <div class="overflowpanel"> <div class="code">
@@ -71,7 +71,7 @@
<pre style="margin: 0px;">&nbsp; );</pre> <pre style="margin: 0px;">&nbsp; );</pre>
<pre style="margin: 0px;">&nbsp;</pre> <pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">JsonSerializer</span> serializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">JsonSerializer</span>();</pre> <pre style="margin: 0px;"><span style="color: #2b91af;">JsonSerializer</span> serializer = <span style="color: blue;">new</span> <span style="color: #2b91af;">JsonSerializer</span>();</pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">Person</span> p = (<span style="color: #2b91af;">Person</span>)serializer.Deserialize(<span style="color: blue;">new</span> <span style="color: #2b91af;">JsonTokenReader</span>(o), <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">Person</span>));</pre> <pre style="margin: 0px;"><span style="color: #2b91af;">Person</span> p = (<span style="color: #2b91af;">Person</span>)serializer.Deserialize(<span style="color: blue;">new</span> <span style="color: #2b91af;">JTokenReader</span>(o), <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">Person</span>));</pre>
<pre style="margin: 0px;">&nbsp;</pre> <pre style="margin: 0px;">&nbsp;</pre>
<pre style="margin: 0px;"><span style="color: green;">// John Smith</span></pre> <pre style="margin: 0px;"><span style="color: green;">// John Smith</span></pre>
<pre style="margin: 0px;"><span style="color: #2b91af;">Console</span>.WriteLine(p.Name);</pre> <pre style="margin: 0px;"><span style="color: #2b91af;">Console</span>.WriteLine(p.Name);</pre>
@@ -33,7 +33,7 @@ using Newtonsoft.Json.Linq;
namespace Newtonsoft.Json.Tests namespace Newtonsoft.Json.Tests
{ {
public class JsonTokenReaderTest : TestFixtureBase public class JTokenReaderTest : TestFixtureBase
{ {
[Test] [Test]
public void YahooFinance() public void YahooFinance()
@@ -46,7 +46,7 @@ namespace Newtonsoft.Json.Tests
new JProperty("Test4", null) new JProperty("Test4", null)
); );
using (JsonTokenReader jsonReader = new JsonTokenReader(o)) using (JTokenReader jsonReader = new JTokenReader(o))
{ {
IJsonLineInfo lineInfo = jsonReader; IJsonLineInfo lineInfo = jsonReader;
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json.Tests
Assert.IsFalse(jsonReader.Read()); Assert.IsFalse(jsonReader.Read());
} }
using (JsonReader jsonReader = new JsonTokenReader(o.Property("Test2"))) using (JsonReader jsonReader = new JTokenReader(o.Property("Test2")))
{ {
Assert.IsTrue(jsonReader.Read()); Assert.IsTrue(jsonReader.Read());
Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType);
@@ -125,7 +125,7 @@ namespace Newtonsoft.Json.Tests
JObject o = JObject.Parse(input); JObject o = JObject.Parse(input);
using (JsonTokenReader jsonReader = new JsonTokenReader(o)) using (JTokenReader jsonReader = new JTokenReader(o))
{ {
IJsonLineInfo lineInfo = jsonReader; IJsonLineInfo lineInfo = jsonReader;
@@ -34,13 +34,13 @@ using System.Linq;
namespace Newtonsoft.Json.Tests namespace Newtonsoft.Json.Tests
{ {
public class JsonTokenWriterTest : TestFixtureBase public class JTokenWriterTest : TestFixtureBase
{ {
[Test] [Test]
public void ValueFormatting() public void ValueFormatting()
{ {
JToken root; JToken root;
using (JsonTokenWriter jsonWriter = new JsonTokenWriter()) using (JTokenWriter jsonWriter = new JTokenWriter())
{ {
jsonWriter.WriteStartArray(); jsonWriter.WriteStartArray();
jsonWriter.WriteValue('@'); jsonWriter.WriteValue('@');
@@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Tests
[Test] [Test]
public void State() public void State()
{ {
using (JsonWriter jsonWriter = new JsonTokenWriter()) using (JsonWriter jsonWriter = new JTokenWriter())
{ {
Assert.AreEqual(WriteState.Start, jsonWriter.WriteState); Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
@@ -246,13 +246,13 @@ Parameter name: arrayIndex")]
JObject o = JObject.FromObject(raw); JObject o = JObject.FromObject(raw);
Assert.AreEqual("FirstNameValue", (string)o["first_name"]); Assert.AreEqual("FirstNameValue", (string)o["first_name"]);
Assert.AreEqual(JsonTokenType.Raw, ((JValue)o["RawContent"]).Type); Assert.AreEqual(JTokenType.Raw, ((JValue)o["RawContent"]).Type);
Assert.AreEqual("[1,2,3,4,5]", (string)o["RawContent"]); Assert.AreEqual("[1,2,3,4,5]", (string)o["RawContent"]);
Assert.AreEqual("LastNameValue", (string)o["last_name"]); Assert.AreEqual("LastNameValue", (string)o["last_name"]);
} }
[Test] [Test]
public void JsonTokenReader() public void JTokenReader()
{ {
PersonRaw raw = new PersonRaw PersonRaw raw = new PersonRaw
{ {
@@ -263,7 +263,7 @@ Parameter name: arrayIndex")]
JObject o = JObject.FromObject(raw); JObject o = JObject.FromObject(raw);
JsonReader reader = new JsonTokenReader(o); JsonReader reader = new JTokenReader(o);
Assert.IsTrue(reader.Read()); Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType); Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
@@ -304,7 +304,7 @@ Parameter name: arrayIndex")]
JObject o = JObject.FromObject(raw); JObject o = JObject.FromObject(raw);
JsonReader reader = new JsonTokenReader(o); JsonReader reader = new JTokenReader(o);
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
raw = (PersonRaw)serializer.Deserialize(reader, typeof(PersonRaw)); raw = (PersonRaw)serializer.Deserialize(reader, typeof(PersonRaw));
@@ -33,7 +33,7 @@ namespace Newtonsoft.Json.Tests.Linq
property = JProperty.Load(reader); property = JProperty.Load(reader);
Assert.AreEqual("propertyname", property.Name); Assert.AreEqual("propertyname", property.Name);
Assert.IsTrue(JToken.DeepEquals(new JValue(null, JsonTokenType.Null), property.Value)); Assert.IsTrue(JToken.DeepEquals(new JValue(null, JTokenType.Null), property.Value));
Assert.AreEqual(JsonToken.EndObject, reader.TokenType); Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
} }
@@ -39,23 +39,23 @@ namespace Newtonsoft.Json.Tests.Linq
{ {
JValue v = new JValue(true); JValue v = new JValue(true);
Assert.AreEqual(true, v.Value); Assert.AreEqual(true, v.Value);
Assert.AreEqual(JsonTokenType.Boolean, v.Type); Assert.AreEqual(JTokenType.Boolean, v.Type);
v.Value = "Pie"; v.Value = "Pie";
Assert.AreEqual("Pie", v.Value); Assert.AreEqual("Pie", v.Value);
Assert.AreEqual(JsonTokenType.String, v.Type); Assert.AreEqual(JTokenType.String, v.Type);
v.Value = null; v.Value = null;
Assert.AreEqual(null, v.Value); Assert.AreEqual(null, v.Value);
Assert.AreEqual(JsonTokenType.Null, v.Type); Assert.AreEqual(JTokenType.Null, v.Type);
v.Value = (int?)null; v.Value = (int?)null;
Assert.AreEqual(null, v.Value); Assert.AreEqual(null, v.Value);
Assert.AreEqual(JsonTokenType.Null, v.Type); Assert.AreEqual(JTokenType.Null, v.Type);
v.Value = "Pie"; v.Value = "Pie";
Assert.AreEqual("Pie", v.Value); Assert.AreEqual("Pie", v.Value);
Assert.AreEqual(JsonTokenType.String, v.Type); Assert.AreEqual(JTokenType.String, v.Type);
} }
[Test] [Test]
@@ -63,11 +63,11 @@ namespace Newtonsoft.Json.Tests.Linq
{ {
JValue commentValue = JValue.CreateComment(null); JValue commentValue = JValue.CreateComment(null);
Assert.AreEqual(null, commentValue.Value); Assert.AreEqual(null, commentValue.Value);
Assert.AreEqual(JsonTokenType.Comment, commentValue.Type); Assert.AreEqual(JTokenType.Comment, commentValue.Type);
commentValue.Value = "Comment"; commentValue.Value = "Comment";
Assert.AreEqual("Comment", commentValue.Value); Assert.AreEqual("Comment", commentValue.Value);
Assert.AreEqual(JsonTokenType.Comment, commentValue.Type); Assert.AreEqual(JTokenType.Comment, commentValue.Type);
} }
[Test] [Test]
@@ -75,7 +75,7 @@ namespace Newtonsoft.Json.Tests.Linq
{ {
JValue stringValue = JValue.CreateString(null); JValue stringValue = JValue.CreateString(null);
Assert.AreEqual(null, stringValue.Value); Assert.AreEqual(null, stringValue.Value);
Assert.AreEqual(JsonTokenType.String, stringValue.Type); Assert.AreEqual(JTokenType.String, stringValue.Type);
} }
[Test] [Test]
@@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Tests.Linq
); );
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
Person p = (Person)serializer.Deserialize(new JsonTokenReader(o), typeof(Person)); Person p = (Person)serializer.Deserialize(new JTokenReader(o), typeof(Person));
// John Smith // John Smith
Console.WriteLine(p.Name); Console.WriteLine(p.Name);
@@ -589,8 +589,8 @@ keyword such as type of business.""
JsonSerializer jsonSerializer = new JsonSerializer(); JsonSerializer jsonSerializer = new JsonSerializer();
JsonTokenWriter jsonWriter; JTokenWriter jsonWriter;
using (jsonWriter = new JsonTokenWriter()) using (jsonWriter = new JTokenWriter())
{ {
jsonSerializer.Serialize(jsonWriter, testDates); jsonSerializer.Serialize(jsonWriter, testDates);
} }
@@ -60,6 +60,8 @@
<ItemGroup> <ItemGroup>
<Compile Include="Converters\BinaryConverterTests.cs" /> <Compile Include="Converters\BinaryConverterTests.cs" />
<Compile Include="Converters\StringEnumConverterTests.cs" /> <Compile Include="Converters\StringEnumConverterTests.cs" />
<Compile Include="JTokenReaderTest.cs" />
<Compile Include="JTokenWriterTest.cs" />
<Compile Include="Serialization\CamelCaseMappingResolverTests.cs" /> <Compile Include="Serialization\CamelCaseMappingResolverTests.cs" />
<Compile Include="JsonValidatingReaderTests.cs" /> <Compile Include="JsonValidatingReaderTests.cs" />
<Compile Include="Schema\ExtensionsTests.cs" /> <Compile Include="Schema\ExtensionsTests.cs" />
@@ -120,8 +122,6 @@
<Compile Include="JsonSerializerTest.cs" /> <Compile Include="JsonSerializerTest.cs" />
<Compile Include="JsonTextReaderTest.cs" /> <Compile Include="JsonTextReaderTest.cs" />
<Compile Include="JsonTextWriterTest.cs" /> <Compile Include="JsonTextWriterTest.cs" />
<Compile Include="JsonTokenReaderTest.cs" />
<Compile Include="JsonTokenWriterTest.cs" />
<Compile Include="Linq\JArrayTests.cs" /> <Compile Include="Linq\JArrayTests.cs" />
<Compile Include="Linq\JObjectTests.cs" /> <Compile Include="Linq\JObjectTests.cs" />
<Compile Include="Linq\JTokenEqualityComparerTests.cs" /> <Compile Include="Linq\JTokenEqualityComparerTests.cs" />
@@ -65,6 +65,8 @@
<ItemGroup> <ItemGroup>
<Compile Include="Converters\BinaryConverterTests.cs" /> <Compile Include="Converters\BinaryConverterTests.cs" />
<Compile Include="Converters\StringEnumConverterTests.cs" /> <Compile Include="Converters\StringEnumConverterTests.cs" />
<Compile Include="JTokenReaderTest.cs" />
<Compile Include="JTokenWriterTest.cs" />
<Compile Include="Serialization\CamelCaseMappingResolverTests.cs" /> <Compile Include="Serialization\CamelCaseMappingResolverTests.cs" />
<Compile Include="JsonValidatingReaderTests.cs" /> <Compile Include="JsonValidatingReaderTests.cs" />
<Compile Include="Schema\ExtensionsTests.cs" /> <Compile Include="Schema\ExtensionsTests.cs" />
@@ -125,8 +127,6 @@
<Compile Include="JsonSerializerTest.cs" /> <Compile Include="JsonSerializerTest.cs" />
<Compile Include="JsonTextReaderTest.cs" /> <Compile Include="JsonTextReaderTest.cs" />
<Compile Include="JsonTextWriterTest.cs" /> <Compile Include="JsonTextWriterTest.cs" />
<Compile Include="JsonTokenReaderTest.cs" />
<Compile Include="JsonTokenWriterTest.cs" />
<Compile Include="Linq\JArrayTests.cs" /> <Compile Include="Linq\JArrayTests.cs" />
<Compile Include="Linq\JObjectTests.cs" /> <Compile Include="Linq\JObjectTests.cs" />
<Compile Include="Linq\JTokenEqualityComparerTests.cs" /> <Compile Include="Linq\JTokenEqualityComparerTests.cs" />
@@ -142,8 +142,8 @@
<Compile Include="JsonSerializerTest.cs" /> <Compile Include="JsonSerializerTest.cs" />
<Compile Include="JsonTextReaderTest.cs" /> <Compile Include="JsonTextReaderTest.cs" />
<Compile Include="JsonTextWriterTest.cs" /> <Compile Include="JsonTextWriterTest.cs" />
<Compile Include="JsonTokenReaderTest.cs" /> <Compile Include="JTokenReaderTest.cs" />
<Compile Include="JsonTokenWriterTest.cs" /> <Compile Include="JTokenWriterTest.cs" />
<Compile Include="Linq\JArrayTests.cs" /> <Compile Include="Linq\JArrayTests.cs" />
<Compile Include="Linq\JObjectTests.cs" /> <Compile Include="Linq\JObjectTests.cs" />
<Compile Include="Linq\JTokenEqualityComparerTests.cs" /> <Compile Include="Linq\JTokenEqualityComparerTests.cs" />
@@ -378,7 +378,7 @@ namespace Newtonsoft.Json.Tests.Schema
DirectoryInfo temp = new DirectoryInfo(@"c:\temp"); DirectoryInfo temp = new DirectoryInfo(@"c:\temp");
JsonTokenWriter jsonWriter = new JsonTokenWriter(); JTokenWriter jsonWriter = new JTokenWriter();
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new IsoDateTimeConverter()); serializer.Converters.Add(new IsoDateTimeConverter());
serializer.MappingResolver = new CustomDirectoryInfoMapper(); serializer.MappingResolver = new CustomDirectoryInfoMapper();
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Tests.Serialization
} }
[Test] [Test]
public void JsonTokenWriter() public void JTokenWriter()
{ {
JsonIgnoreAttributeOnClassTestClass ignoreAttributeOnClassTestClass = new JsonIgnoreAttributeOnClassTestClass(); JsonIgnoreAttributeOnClassTestClass ignoreAttributeOnClassTestClass = new JsonIgnoreAttributeOnClassTestClass();
ignoreAttributeOnClassTestClass.Field = int.MinValue; ignoreAttributeOnClassTestClass.Field = int.MinValue;
@@ -76,7 +76,7 @@ namespace Newtonsoft.Json.Tests.Serialization
JsonSerializer serializer = new JsonSerializer(); JsonSerializer serializer = new JsonSerializer();
serializer.MappingResolver = new CamelCaseMappingResolver(); serializer.MappingResolver = new CamelCaseMappingResolver();
JsonTokenWriter writer = new JsonTokenWriter(); JTokenWriter writer = new JTokenWriter();
serializer.Serialize(writer, ignoreAttributeOnClassTestClass); serializer.Serialize(writer, ignoreAttributeOnClassTestClass);
+23 -23
View File
@@ -115,7 +115,7 @@ namespace Newtonsoft.Json
private int _top; private int _top;
private readonly List<JsonTokenType> _stack; private readonly List<JTokenType> _stack;
/// <summary> /// <summary>
/// Gets the quotation mark character used to enclose the value of a string. /// Gets the quotation mark character used to enclose the value of a string.
@@ -173,27 +173,27 @@ namespace Newtonsoft.Json
{ {
//_testBuffer = new StringBuilder(); //_testBuffer = new StringBuilder();
_currentState = State.Start; _currentState = State.Start;
_stack = new List<JsonTokenType>(); _stack = new List<JTokenType>();
_top = 0; _top = 0;
Push(JsonTokenType.None); Push(JTokenType.None);
} }
private void Push(JsonTokenType value) private void Push(JTokenType value)
{ {
_stack.Add(value); _stack.Add(value);
_top++; _top++;
} }
private JsonTokenType Pop() private JTokenType Pop()
{ {
JsonTokenType value = Peek(); JTokenType value = Peek();
_stack.RemoveAt(_stack.Count - 1); _stack.RemoveAt(_stack.Count - 1);
_top--; _top--;
return value; return value;
} }
private JsonTokenType Peek() private JTokenType Peek()
{ {
return _stack[_top - 1]; return _stack[_top - 1];
} }
@@ -241,15 +241,15 @@ namespace Newtonsoft.Json
{ {
case JsonToken.StartObject: case JsonToken.StartObject:
_currentState = State.ObjectStart; _currentState = State.ObjectStart;
Push(JsonTokenType.Object); Push(JTokenType.Object);
break; break;
case JsonToken.StartArray: case JsonToken.StartArray:
_currentState = State.ArrayStart; _currentState = State.ArrayStart;
Push(JsonTokenType.Array); Push(JTokenType.Array);
break; break;
case JsonToken.StartConstructor: case JsonToken.StartConstructor:
_currentState = State.ConstructorStart; _currentState = State.ConstructorStart;
Push(JsonTokenType.Constructor); Push(JTokenType.Constructor);
break; break;
case JsonToken.EndObject: case JsonToken.EndObject:
ValidateEnd(JsonToken.EndObject); ValidateEnd(JsonToken.EndObject);
@@ -265,7 +265,7 @@ namespace Newtonsoft.Json
break; break;
case JsonToken.PropertyName: case JsonToken.PropertyName:
_currentState = State.Property; _currentState = State.Property;
Push(JsonTokenType.Property); Push(JTokenType.Property);
break; break;
case JsonToken.Undefined: case JsonToken.Undefined:
case JsonToken.Integer: case JsonToken.Integer:
@@ -279,8 +279,8 @@ namespace Newtonsoft.Json
break; break;
} }
JsonTokenType current = Peek(); JTokenType current = Peek();
if (current == JsonTokenType.Property && _currentState == State.PostValue) if (current == JTokenType.Property && _currentState == State.PostValue)
Pop(); Pop();
if (value != null) if (value != null)
@@ -297,7 +297,7 @@ namespace Newtonsoft.Json
private void ValidateEnd(JsonToken endToken) private void ValidateEnd(JsonToken endToken)
{ {
JsonTokenType currentObject = Pop(); JTokenType currentObject = Pop();
if (GetTypeForCloseToken(endToken) != currentObject) if (GetTypeForCloseToken(endToken) != currentObject)
throw new JsonReaderException("JsonToken {0} is not valid for closing JsonType {1}.".FormatWith(CultureInfo.InvariantCulture, endToken, currentObject)); throw new JsonReaderException("JsonToken {0} is not valid for closing JsonType {1}.".FormatWith(CultureInfo.InvariantCulture, endToken, currentObject));
@@ -308,20 +308,20 @@ namespace Newtonsoft.Json
/// </summary> /// </summary>
protected void SetStateBasedOnCurrent() protected void SetStateBasedOnCurrent()
{ {
JsonTokenType currentObject = Peek(); JTokenType currentObject = Peek();
switch (currentObject) switch (currentObject)
{ {
case JsonTokenType.Object: case JTokenType.Object:
_currentState = State.Object; _currentState = State.Object;
break; break;
case JsonTokenType.Array: case JTokenType.Array:
_currentState = State.Array; _currentState = State.Array;
break; break;
case JsonTokenType.Constructor: case JTokenType.Constructor:
_currentState = State.Constructor; _currentState = State.Constructor;
break; break;
case JsonTokenType.None: case JTokenType.None:
_currentState = State.Finished; _currentState = State.Finished;
break; break;
default: default:
@@ -357,16 +357,16 @@ namespace Newtonsoft.Json
} }
} }
private JsonTokenType GetTypeForCloseToken(JsonToken token) private JTokenType GetTypeForCloseToken(JsonToken token)
{ {
switch (token) switch (token)
{ {
case JsonToken.EndObject: case JsonToken.EndObject:
return JsonTokenType.Object; return JTokenType.Object;
case JsonToken.EndArray: case JsonToken.EndArray:
return JsonTokenType.Array; return JTokenType.Array;
case JsonToken.EndConstructor: case JsonToken.EndConstructor:
return JsonTokenType.Constructor; return JTokenType.Constructor;
default: default:
throw new JsonReaderException("Not a valid close JsonToken: " + token); throw new JsonReaderException("Not a valid close JsonToken: " + token);
} }
+1 -1
View File
@@ -238,7 +238,7 @@ namespace Newtonsoft.Json
private JToken CreateJToken(JsonReader reader) private JToken CreateJToken(JsonReader reader)
{ {
JToken token; JToken token;
using (JsonTokenWriter writer = new JsonTokenWriter()) using (JTokenWriter writer = new JTokenWriter())
{ {
writer.WriteToken(reader); writer.WriteToken(reader);
token = writer.Token; token = writer.Token;
+11 -11
View File
@@ -39,7 +39,7 @@ namespace Newtonsoft.Json
{ {
private class SchemaScope private class SchemaScope
{ {
private readonly JsonTokenType _tokenType; private readonly JTokenType _tokenType;
private readonly JsonSchemaModel _schema; private readonly JsonSchemaModel _schema;
private readonly Dictionary<string, bool> _requiredProperties; private readonly Dictionary<string, bool> _requiredProperties;
@@ -56,12 +56,12 @@ namespace Newtonsoft.Json
get { return _requiredProperties; } get { return _requiredProperties; }
} }
public JsonTokenType TokenType public JTokenType TokenType
{ {
get { return _tokenType; } get { return _tokenType; }
} }
public SchemaScope(JsonTokenType tokenType, JsonSchemaModel schema) public SchemaScope(JTokenType tokenType, JsonSchemaModel schema)
{ {
_tokenType = tokenType; _tokenType = tokenType;
_schema = schema; _schema = schema;
@@ -154,9 +154,9 @@ namespace Newtonsoft.Json
switch (_currentScope.TokenType) switch (_currentScope.TokenType)
{ {
case JsonTokenType.None: case JTokenType.None:
return _currentScope.Schema; return _currentScope.Schema;
case JsonTokenType.Object: case JTokenType.Object:
if (_currentScope.CurrentPropertyName == null) if (_currentScope.CurrentPropertyName == null)
throw new Exception("CurrentPropertyName has not been set on scope."); throw new Exception("CurrentPropertyName has not been set on scope.");
@@ -165,7 +165,7 @@ namespace Newtonsoft.Json
return propertySchema; return propertySchema;
return (CurrentSchema.AllowAdditionalProperties) ? CurrentSchema.AdditionalProperties : null; return (CurrentSchema.AllowAdditionalProperties) ? CurrentSchema.AdditionalProperties : null;
case JsonTokenType.Array: case JTokenType.Array:
if (!CollectionUtils.IsNullOrEmpty(CurrentSchema.Items)) if (!CollectionUtils.IsNullOrEmpty(CurrentSchema.Items))
{ {
if (CurrentSchema.Items.Count == 1) if (CurrentSchema.Items.Count == 1)
@@ -176,7 +176,7 @@ namespace Newtonsoft.Json
} }
return (CurrentSchema.AllowAdditionalProperties) ? CurrentSchema.AdditionalProperties : null; return (CurrentSchema.AllowAdditionalProperties) ? CurrentSchema.AdditionalProperties : null;
case JsonTokenType.Constructor: case JTokenType.Constructor:
return null; return null;
default: default:
throw new ArgumentOutOfRangeException("TokenType", "Unexpected token type: {0}".FormatWith(CultureInfo.InvariantCulture, _currentScope.TokenType)); throw new ArgumentOutOfRangeException("TokenType", "Unexpected token type: {0}".FormatWith(CultureInfo.InvariantCulture, _currentScope.TokenType));
@@ -296,17 +296,17 @@ namespace Newtonsoft.Json
JsonSchemaModel objectSchema = (ValidateObject(CurrentMemberSchema)) JsonSchemaModel objectSchema = (ValidateObject(CurrentMemberSchema))
? CurrentMemberSchema ? CurrentMemberSchema
: null; : null;
Push(new SchemaScope(JsonTokenType.Object, objectSchema)); Push(new SchemaScope(JTokenType.Object, objectSchema));
break; break;
case JsonToken.StartArray: case JsonToken.StartArray:
ProcessValue(); ProcessValue();
JsonSchemaModel arraySchema = (ValidateArray(CurrentMemberSchema)) JsonSchemaModel arraySchema = (ValidateArray(CurrentMemberSchema))
? CurrentMemberSchema ? CurrentMemberSchema
: null; : null;
Push(new SchemaScope(JsonTokenType.Array, arraySchema)); Push(new SchemaScope(JTokenType.Array, arraySchema));
break; break;
case JsonToken.StartConstructor: case JsonToken.StartConstructor:
Push(new SchemaScope(JsonTokenType.Constructor, null)); Push(new SchemaScope(JTokenType.Constructor, null));
break; break;
case JsonToken.PropertyName: case JsonToken.PropertyName:
ValidatePropertyName(CurrentSchema); ValidatePropertyName(CurrentSchema);
@@ -457,7 +457,7 @@ namespace Newtonsoft.Json
private void ProcessValue() private void ProcessValue()
{ {
if (_currentScope != null && _currentScope.TokenType == JsonTokenType.Array) if (_currentScope != null && _currentScope.TokenType == JTokenType.Array)
{ {
_currentScope.ArrayItemCount++; _currentScope.ArrayItemCount++;
+27 -27
View File
@@ -121,7 +121,7 @@ namespace Newtonsoft.Json
private int _top; private int _top;
private List<JsonTokenType> _stack; private List<JTokenType> _stack;
private State _currentState; private State _currentState;
private Formatting _formatting; private Formatting _formatting;
private List<object> _serializeStack; private List<object> _serializeStack;
@@ -192,13 +192,13 @@ namespace Newtonsoft.Json
/// </summary> /// </summary>
public JsonWriter() public JsonWriter()
{ {
_stack = new List<JsonTokenType>(8); _stack = new List<JTokenType>(8);
_stack.Add(JsonTokenType.None); _stack.Add(JTokenType.None);
_currentState = State.Start; _currentState = State.Start;
_formatting = Formatting.None; _formatting = Formatting.None;
} }
private void Push(JsonTokenType value) private void Push(JTokenType value)
{ {
_top++; _top++;
if (_stack.Count <= _top) if (_stack.Count <= _top)
@@ -207,15 +207,15 @@ namespace Newtonsoft.Json
_stack[_top] = value; _stack[_top] = value;
} }
private JsonTokenType Pop() private JTokenType Pop()
{ {
JsonTokenType value = Peek(); JTokenType value = Peek();
_top--; _top--;
return value; return value;
} }
private JsonTokenType Peek() private JTokenType Peek()
{ {
return _stack[_top]; return _stack[_top];
} }
@@ -239,7 +239,7 @@ namespace Newtonsoft.Json
public virtual void WriteStartObject() public virtual void WriteStartObject()
{ {
AutoComplete(JsonToken.StartObject); AutoComplete(JsonToken.StartObject);
Push(JsonTokenType.Object); Push(JTokenType.Object);
} }
/// <summary> /// <summary>
@@ -256,7 +256,7 @@ namespace Newtonsoft.Json
public virtual void WriteStartArray() public virtual void WriteStartArray()
{ {
AutoComplete(JsonToken.StartArray); AutoComplete(JsonToken.StartArray);
Push(JsonTokenType.Array); Push(JTokenType.Array);
} }
/// <summary> /// <summary>
@@ -274,7 +274,7 @@ namespace Newtonsoft.Json
public virtual void WriteStartConstructor(string name) public virtual void WriteStartConstructor(string name)
{ {
AutoComplete(JsonToken.StartConstructor); AutoComplete(JsonToken.StartConstructor);
Push(JsonTokenType.Constructor); Push(JTokenType.Constructor);
} }
/// <summary> /// <summary>
@@ -433,17 +433,17 @@ namespace Newtonsoft.Json
} }
} }
private void WriteEnd(JsonTokenType type) private void WriteEnd(JTokenType type)
{ {
switch (type) switch (type)
{ {
case JsonTokenType.Object: case JTokenType.Object:
WriteEndObject(); WriteEndObject();
break; break;
case JsonTokenType.Array: case JTokenType.Array:
WriteEndArray(); WriteEndArray();
break; break;
case JsonTokenType.Constructor: case JTokenType.Constructor:
WriteEndConstructor(); WriteEndConstructor();
break; break;
default: default:
@@ -459,30 +459,30 @@ namespace Newtonsoft.Json
} }
} }
private JsonTokenType GetTypeForCloseToken(JsonToken token) private JTokenType GetTypeForCloseToken(JsonToken token)
{ {
switch (token) switch (token)
{ {
case JsonToken.EndObject: case JsonToken.EndObject:
return JsonTokenType.Object; return JTokenType.Object;
case JsonToken.EndArray: case JsonToken.EndArray:
return JsonTokenType.Array; return JTokenType.Array;
case JsonToken.EndConstructor: case JsonToken.EndConstructor:
return JsonTokenType.Constructor; return JTokenType.Constructor;
default: default:
throw new JsonWriterException("No type for token: " + token); throw new JsonWriterException("No type for token: " + token);
} }
} }
private JsonToken GetCloseTokenForType(JsonTokenType type) private JsonToken GetCloseTokenForType(JTokenType type)
{ {
switch (type) switch (type)
{ {
case JsonTokenType.Object: case JTokenType.Object:
return JsonToken.EndObject; return JsonToken.EndObject;
case JsonTokenType.Array: case JTokenType.Array:
return JsonToken.EndArray; return JsonToken.EndArray;
case JsonTokenType.Constructor: case JTokenType.Constructor:
return JsonToken.EndConstructor; return JsonToken.EndConstructor;
default: default:
throw new JsonWriterException("No close token for type: " + type); throw new JsonWriterException("No close token for type: " + type);
@@ -519,20 +519,20 @@ namespace Newtonsoft.Json
WriteEnd(token); WriteEnd(token);
} }
JsonTokenType currentLevelType = Peek(); JTokenType currentLevelType = Peek();
switch (currentLevelType) switch (currentLevelType)
{ {
case JsonTokenType.Object: case JTokenType.Object:
_currentState = State.Object; _currentState = State.Object;
break; break;
case JsonTokenType.Array: case JTokenType.Array:
_currentState = State.Array; _currentState = State.Array;
break; break;
case JsonTokenType.Constructor: case JTokenType.Constructor:
_currentState = State.Array; _currentState = State.Array;
break; break;
case JsonTokenType.None: case JTokenType.None:
_currentState = State.Start; _currentState = State.Start;
break; break;
default: default:
+4 -4
View File
@@ -42,9 +42,9 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public override JsonTokenType Type public override JTokenType Type
{ {
get { return JsonTokenType.Array; } get { return JTokenType.Array; }
} }
/// <summary> /// <summary>
@@ -134,7 +134,7 @@ namespace Newtonsoft.Json.Linq
{ {
ValidationUtils.ArgumentNotNull(o, "o"); ValidationUtils.ArgumentNotNull(o, "o");
if (o.Type == JsonTokenType.Property) if (o.Type == JTokenType.Property)
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type)); throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
} }
@@ -147,7 +147,7 @@ namespace Newtonsoft.Json.Linq
{ {
JToken token = FromObjectInternal(o); JToken token = FromObjectInternal(o);
if (token.Type != JsonTokenType.Array) if (token.Type != JTokenType.Array)
throw new ArgumentException("Object serialized to {0}. JArray instance expected.".FormatWith(CultureInfo.InvariantCulture, token.Type)); throw new ArgumentException("Object serialized to {0}. JArray instance expected.".FormatWith(CultureInfo.InvariantCulture, token.Type));
return (JArray)token; return (JArray)token;
+3 -3
View File
@@ -53,9 +53,9 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public override JsonTokenType Type public override JTokenType Type
{ {
get { return JsonTokenType.Constructor; } get { return JTokenType.Constructor; }
} }
/// <summary> /// <summary>
@@ -117,7 +117,7 @@ namespace Newtonsoft.Json.Linq
switch (o.Type) switch (o.Type)
{ {
case JsonTokenType.Property: case JTokenType.Property:
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type)); throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
} }
} }
+4 -4
View File
@@ -253,7 +253,7 @@ namespace Newtonsoft.Json.Linq
{ {
ValidationUtils.ArgumentNotNull(o, "o"); ValidationUtils.ArgumentNotNull(o, "o");
if (o.Type == JsonTokenType.Property) if (o.Type == JTokenType.Property)
throw new Exception("Can not add {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, o.GetType(), GetType())); throw new Exception("Can not add {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, o.GetType(), GetType()));
} }
@@ -289,7 +289,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>An <see cref="JsonWriter"/> that is ready to have content written to it.</returns> /// <returns>An <see cref="JsonWriter"/> that is ready to have content written to it.</returns>
public JsonWriter CreateWriter() public JsonWriter CreateWriter()
{ {
return new JsonTokenWriter(this); return new JTokenWriter(this);
} }
/// <summary> /// <summary>
@@ -436,12 +436,12 @@ namespace Newtonsoft.Json.Linq
parent.AddObjectSkipNotify(v); parent.AddObjectSkipNotify(v);
break; break;
case JsonToken.Null: case JsonToken.Null:
v = new JValue(null, JsonTokenType.Null); v = new JValue(null, JTokenType.Null);
v.SetLineInfo(lineInfo); v.SetLineInfo(lineInfo);
parent.AddObjectSkipNotify(v); parent.AddObjectSkipNotify(v);
break; break;
case JsonToken.Undefined: case JsonToken.Undefined:
v = new JValue(null, JsonTokenType.Undefined); v = new JValue(null, JTokenType.Undefined);
v.SetLineInfo(lineInfo); v.SetLineInfo(lineInfo);
parent.AddObjectSkipNotify(v); parent.AddObjectSkipNotify(v);
break; break;
+5 -5
View File
@@ -82,7 +82,7 @@ namespace Newtonsoft.Json.Linq
{ {
ValidationUtils.ArgumentNotNull(o, "o"); ValidationUtils.ArgumentNotNull(o, "o");
if (o.Type != JsonTokenType.Property) if (o.Type != JTokenType.Property)
throw new Exception("Can not add {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, o.GetType(), GetType())); throw new Exception("Can not add {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, o.GetType(), GetType()));
JProperty property = (JProperty)o; JProperty property = (JProperty)o;
@@ -100,9 +100,9 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public override JsonTokenType Type public override JTokenType Type
{ {
get { return JsonTokenType.Object; } get { return JTokenType.Object; }
} }
/// <summary> /// <summary>
@@ -228,7 +228,7 @@ namespace Newtonsoft.Json.Linq
{ {
JToken token = FromObjectInternal(o); JToken token = FromObjectInternal(o);
if (token.Type != JsonTokenType.Object) if (token.Type != JTokenType.Object)
throw new ArgumentException("Object serialized to {0}. JObject instance expected.".FormatWith(CultureInfo.InvariantCulture, token.Type)); throw new ArgumentException("Object serialized to {0}. JObject instance expected.".FormatWith(CultureInfo.InvariantCulture, token.Type));
return (JObject)token; return (JObject)token;
@@ -238,7 +238,7 @@ namespace Newtonsoft.Json.Linq
{ {
ValidationUtils.ArgumentNotNull(o, "o"); ValidationUtils.ArgumentNotNull(o, "o");
if (o.Type != JsonTokenType.Property) if (o.Type != JTokenType.Property)
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type)); throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
} }
+3 -3
View File
@@ -86,10 +86,10 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public override JsonTokenType Type public override JTokenType Type
{ {
[DebuggerStepThrough] [DebuggerStepThrough]
get { return JsonTokenType.Property; } get { return JTokenType.Property; }
} }
/// <summary> /// <summary>
@@ -133,7 +133,7 @@ namespace Newtonsoft.Json.Linq
{ {
ValidationUtils.ArgumentNotNull(o, "o"); ValidationUtils.ArgumentNotNull(o, "o");
if (o.Type == JsonTokenType.Property) if (o.Type == JTokenType.Property)
throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type)); throw new ArgumentException("An item of type {0} cannot be added to content.".FormatWith(CultureInfo.InvariantCulture, o.Type));
} }
+9 -9
View File
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public abstract JsonTokenType Type { get; } public abstract JTokenType Type { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether this token has childen tokens. /// Gets a value indicating whether this token has childen tokens.
@@ -376,32 +376,32 @@ namespace Newtonsoft.Json.Linq
private static bool IsNullable(JToken o) private static bool IsNullable(JToken o)
{ {
return (o.Type == JsonTokenType.Undefined || o.Type == JsonTokenType.Null); return (o.Type == JTokenType.Undefined || o.Type == JTokenType.Null);
} }
private static bool ValidateFloat(JToken o, bool nullable) private static bool ValidateFloat(JToken o, bool nullable)
{ {
return (o.Type == JsonTokenType.Float || o.Type == JsonTokenType.Integer || (nullable && IsNullable(o))); return (o.Type == JTokenType.Float || o.Type == JTokenType.Integer || (nullable && IsNullable(o)));
} }
private static bool ValidateInteger(JToken o, bool nullable) private static bool ValidateInteger(JToken o, bool nullable)
{ {
return (o.Type == JsonTokenType.Integer || (nullable && IsNullable(o))); return (o.Type == JTokenType.Integer || (nullable && IsNullable(o)));
} }
private static bool ValidateDate(JToken o, bool nullable) private static bool ValidateDate(JToken o, bool nullable)
{ {
return (o.Type == JsonTokenType.Date || (nullable && IsNullable(o))); return (o.Type == JTokenType.Date || (nullable && IsNullable(o)));
} }
private static bool ValidateBoolean(JToken o, bool nullable) private static bool ValidateBoolean(JToken o, bool nullable)
{ {
return (o.Type == JsonTokenType.Boolean || (nullable && IsNullable(o))); return (o.Type == JTokenType.Boolean || (nullable && IsNullable(o)));
} }
private static bool ValidateString(JToken o) private static bool ValidateString(JToken o)
{ {
return (o.Type == JsonTokenType.String || o.Type == JsonTokenType.Comment || o.Type == JsonTokenType.Raw || IsNullable(o)); return (o.Type == JTokenType.String || o.Type == JTokenType.Comment || o.Type == JTokenType.Raw || IsNullable(o));
} }
private static string GetType(JToken t) private static string GetType(JToken t)
@@ -763,7 +763,7 @@ namespace Newtonsoft.Json.Linq
public JsonReader CreateReader() public JsonReader CreateReader()
{ {
return new JsonTokenReader(this); return new JTokenReader(this);
} }
internal static JToken FromObjectInternal(object o) internal static JToken FromObjectInternal(object o)
@@ -773,7 +773,7 @@ namespace Newtonsoft.Json.Linq
JsonSerializer jsonSerializer = new JsonSerializer(); JsonSerializer jsonSerializer = new JsonSerializer();
JToken token; JToken token;
using (JsonTokenWriter jsonWriter = new JsonTokenWriter()) using (JTokenWriter jsonWriter = new JTokenWriter())
{ {
jsonSerializer.Serialize(jsonWriter, o); jsonSerializer.Serialize(jsonWriter, o);
token = jsonWriter.Token; token = jsonWriter.Token;
@@ -9,17 +9,17 @@ namespace Newtonsoft.Json.Linq
/// <summary> /// <summary>
/// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data. /// Represents a reader that provides fast, non-cached, forward-only access to serialized Json data.
/// </summary> /// </summary>
public class JsonTokenReader : JsonReader, IJsonLineInfo public class JTokenReader : JsonReader, IJsonLineInfo
{ {
private readonly JToken _root; private readonly JToken _root;
private JToken _parent; private JToken _parent;
private JToken _current; private JToken _current;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonTokenReader"/> class. /// Initializes a new instance of the <see cref="JTokenReader"/> class.
/// </summary> /// </summary>
/// <param name="token">The token to read from.</param> /// <param name="token">The token to read from.</param>
public JsonTokenReader(JToken token) public JTokenReader(JToken token)
{ {
ValidationUtils.ArgumentNotNull(token, "token"); ValidationUtils.ArgumentNotNull(token, "token");
@@ -84,13 +84,13 @@ namespace Newtonsoft.Json.Linq
{ {
switch (c.Type) switch (c.Type)
{ {
case JsonTokenType.Object: case JTokenType.Object:
return JsonToken.EndObject; return JsonToken.EndObject;
case JsonTokenType.Array: case JTokenType.Array:
return JsonToken.EndArray; return JsonToken.EndArray;
case JsonTokenType.Constructor: case JTokenType.Constructor:
return JsonToken.EndConstructor; return JsonToken.EndConstructor;
case JsonTokenType.Property: case JTokenType.Property:
return null; return null;
default: default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", c.Type, "Unexpected JContainer type."); throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", c.Type, "Unexpected JContainer type.");
@@ -133,47 +133,47 @@ namespace Newtonsoft.Json.Linq
{ {
switch (token.Type) switch (token.Type)
{ {
case JsonTokenType.Object: case JTokenType.Object:
SetToken(JsonToken.StartObject); SetToken(JsonToken.StartObject);
break; break;
case JsonTokenType.Array: case JTokenType.Array:
SetToken(JsonToken.StartArray); SetToken(JsonToken.StartArray);
break; break;
case JsonTokenType.Constructor: case JTokenType.Constructor:
SetToken(JsonToken.StartConstructor); SetToken(JsonToken.StartConstructor);
break; break;
case JsonTokenType.Property: case JTokenType.Property:
SetToken(JsonToken.PropertyName, ((JProperty)token).Name); SetToken(JsonToken.PropertyName, ((JProperty)token).Name);
break; break;
case JsonTokenType.Comment: case JTokenType.Comment:
SetToken(JsonToken.Comment, ((JValue)token).Value); SetToken(JsonToken.Comment, ((JValue)token).Value);
break; break;
case JsonTokenType.Integer: case JTokenType.Integer:
SetToken(JsonToken.Integer, ((JValue)token).Value); SetToken(JsonToken.Integer, ((JValue)token).Value);
break; break;
case JsonTokenType.Float: case JTokenType.Float:
SetToken(JsonToken.Float, ((JValue)token).Value); SetToken(JsonToken.Float, ((JValue)token).Value);
break; break;
case JsonTokenType.String: case JTokenType.String:
SetToken(JsonToken.String, ((JValue)token).Value); SetToken(JsonToken.String, ((JValue)token).Value);
break; break;
case JsonTokenType.Boolean: case JTokenType.Boolean:
SetToken(JsonToken.Boolean, ((JValue)token).Value); SetToken(JsonToken.Boolean, ((JValue)token).Value);
break; break;
case JsonTokenType.Null: case JTokenType.Null:
SetToken(JsonToken.Null, ((JValue)token).Value); SetToken(JsonToken.Null, ((JValue)token).Value);
break; break;
case JsonTokenType.Undefined: case JTokenType.Undefined:
SetToken(JsonToken.Undefined, ((JValue)token).Value); SetToken(JsonToken.Undefined, ((JValue)token).Value);
break; break;
case JsonTokenType.Date: case JTokenType.Date:
SetToken(JsonToken.Date, ((JValue)token).Value); SetToken(JsonToken.Date, ((JValue)token).Value);
break; break;
case JsonTokenType.Raw: case JTokenType.Raw:
SetToken(JsonToken.Raw, ((JValue)token).Value); SetToken(JsonToken.Raw, ((JValue)token).Value);
break; break;
default: default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", token.Type, "Unexpected JsonTokenType."); throw MiscellaneousUtils.CreateArgumentOutOfRangeException("Type", token.Type, "Unexpected JTokenType.");
} }
} }
@@ -33,7 +33,7 @@ namespace Newtonsoft.Json.Linq
/// <summary> /// <summary>
/// Specifies the type of token. /// Specifies the type of token.
/// </summary> /// </summary>
public enum JsonTokenType public enum JTokenType
{ {
/// <summary> /// <summary>
/// No token type has been set. /// No token type has been set.
@@ -9,7 +9,7 @@ namespace Newtonsoft.Json.Linq
/// <summary> /// <summary>
/// Represents a writer that provides a fast, non-cached, forward-only way of generating Json data. /// Represents a writer that provides a fast, non-cached, forward-only way of generating Json data.
/// </summary> /// </summary>
public class JsonTokenWriter : JsonWriter public class JTokenWriter : JsonWriter
{ {
private JContainer _token; private JContainer _token;
private JContainer _parent; private JContainer _parent;
@@ -32,10 +32,10 @@ namespace Newtonsoft.Json.Linq
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonTokenWriter"/> class writing to the given <see cref="JContainer"/>. /// Initializes a new instance of the <see cref="JTokenWriter"/> class writing to the given <see cref="JContainer"/>.
/// </summary> /// </summary>
/// <param name="container">The container being written to.</param> /// <param name="container">The container being written to.</param>
public JsonTokenWriter(JContainer container) public JTokenWriter(JContainer container)
{ {
ValidationUtils.ArgumentNotNull(container, "container"); ValidationUtils.ArgumentNotNull(container, "container");
@@ -44,9 +44,9 @@ namespace Newtonsoft.Json.Linq
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonTokenWriter"/> class. /// Initializes a new instance of the <see cref="JTokenWriter"/> class.
/// </summary> /// </summary>
public JsonTokenWriter() public JTokenWriter()
{ {
} }
@@ -89,7 +89,7 @@ namespace Newtonsoft.Json.Linq
{ {
_parent = _parent.Parent; _parent = _parent.Parent;
if (_parent != null && _parent.Type == JsonTokenType.Property) if (_parent != null && _parent.Type == JTokenType.Property)
_parent = _parent.Parent; _parent = _parent.Parent;
} }
@@ -145,7 +145,7 @@ namespace Newtonsoft.Json.Linq
{ {
_parent.Add(value); _parent.Add(value);
if (_parent.Type == JsonTokenType.Property) if (_parent.Type == JTokenType.Property)
_parent = _parent.Parent; _parent = _parent.Parent;
} }
else else
+40 -40
View File
@@ -37,10 +37,10 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
public class JValue : JToken public class JValue : JToken
{ {
private JsonTokenType _valueType; private JTokenType _valueType;
private object _value; private object _value;
internal JValue(object value, JsonTokenType type) internal JValue(object value, JTokenType type)
{ {
_value = value; _value = value;
_valueType = type; _valueType = type;
@@ -60,7 +60,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(long value) public JValue(long value)
: this(value, JsonTokenType.Integer) : this(value, JTokenType.Integer)
{ {
} }
@@ -69,7 +69,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(ulong value) public JValue(ulong value)
: this(value, JsonTokenType.Integer) : this(value, JTokenType.Integer)
{ {
} }
@@ -78,7 +78,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(double value) public JValue(double value)
: this(value, JsonTokenType.Float) : this(value, JTokenType.Float)
{ {
} }
@@ -87,7 +87,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(DateTime value) public JValue(DateTime value)
: this(value, JsonTokenType.Date) : this(value, JTokenType.Date)
{ {
} }
@@ -96,7 +96,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(bool value) public JValue(bool value)
: this(value, JsonTokenType.Boolean) : this(value, JTokenType.Boolean)
{ {
} }
@@ -105,7 +105,7 @@ namespace Newtonsoft.Json.Linq
/// </summary> /// </summary>
/// <param name="value">The value.</param> /// <param name="value">The value.</param>
public JValue(string value) public JValue(string value)
: this(value, JsonTokenType.String) : this(value, JTokenType.String)
{ {
} }
@@ -145,18 +145,18 @@ namespace Newtonsoft.Json.Linq
switch (_valueType) switch (_valueType)
{ {
case JsonTokenType.Integer: case JTokenType.Integer:
if (objA is ulong || objB is ulong) if (objA is ulong || objB is ulong)
return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDecimal(objB, CultureInfo.InvariantCulture)); return Convert.ToDecimal(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDecimal(objB, CultureInfo.InvariantCulture));
else else
return Convert.ToInt64(objA, CultureInfo.InvariantCulture).Equals(Convert.ToInt64(objB, CultureInfo.InvariantCulture)); return Convert.ToInt64(objA, CultureInfo.InvariantCulture).Equals(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
case JsonTokenType.Float: case JTokenType.Float:
return Convert.ToDouble(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDouble(objB, CultureInfo.InvariantCulture)); return Convert.ToDouble(objA, CultureInfo.InvariantCulture).Equals(Convert.ToDouble(objB, CultureInfo.InvariantCulture));
case JsonTokenType.Comment: case JTokenType.Comment:
case JsonTokenType.String: case JTokenType.String:
case JsonTokenType.Boolean: case JTokenType.Boolean:
return objA.Equals(objB); return objA.Equals(objB);
case JsonTokenType.Date: case JTokenType.Date:
return objA.Equals(objB); return objA.Equals(objB);
default: default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", _valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, _valueType)); throw MiscellaneousUtils.CreateArgumentOutOfRangeException("valueType", _valueType, "Unexpected value type: {0}".FormatWith(CultureInfo.InvariantCulture, _valueType));
@@ -175,7 +175,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>A <see cref="JValue"/> comment with the given value.</returns> /// <returns>A <see cref="JValue"/> comment with the given value.</returns>
public static JValue CreateComment(string value) public static JValue CreateComment(string value)
{ {
return new JValue(value, JsonTokenType.Comment); return new JValue(value, JTokenType.Comment);
} }
/// <summary> /// <summary>
@@ -185,7 +185,7 @@ namespace Newtonsoft.Json.Linq
/// <returns>A <see cref="JValue"/> string with the given value.</returns> /// <returns>A <see cref="JValue"/> string with the given value.</returns>
public static JValue CreateString(string value) public static JValue CreateString(string value)
{ {
return new JValue(value, JsonTokenType.String); return new JValue(value, JTokenType.String);
} }
@@ -196,43 +196,43 @@ namespace Newtonsoft.Json.Linq
/// <returns>A <see cref="JValue"/> of raw JSON with the given value.</returns> /// <returns>A <see cref="JValue"/> of raw JSON with the given value.</returns>
public static JValue CreateRaw(string value) public static JValue CreateRaw(string value)
{ {
return new JValue(value, JsonTokenType.Raw); return new JValue(value, JTokenType.Raw);
} }
private static JsonTokenType GetValueType(JsonTokenType? current, object value) private static JTokenType GetValueType(JTokenType? current, object value)
{ {
if (value == null) if (value == null)
return JsonTokenType.Null; return JTokenType.Null;
else if (value is string) else if (value is string)
return GetStringValueType(current); return GetStringValueType(current);
else if (value is long || value is int || value is short || value is sbyte else if (value is long || value is int || value is short || value is sbyte
|| value is ulong || value is uint || value is ushort || value is byte) || value is ulong || value is uint || value is ushort || value is byte)
return JsonTokenType.Integer; return JTokenType.Integer;
else if (value is double || value is float || value is decimal) else if (value is double || value is float || value is decimal)
return JsonTokenType.Float; return JTokenType.Float;
else if (value is DateTime) else if (value is DateTime)
return JsonTokenType.Date; return JTokenType.Date;
else if (value is DateTimeOffset) else if (value is DateTimeOffset)
return JsonTokenType.Date; return JTokenType.Date;
else if (value is bool) else if (value is bool)
return JsonTokenType.Boolean; return JTokenType.Boolean;
throw new ArgumentException("Could not determin JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType())); throw new ArgumentException("Could not determin JSON object type for type {0}.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
} }
private static JsonTokenType GetStringValueType(JsonTokenType? current) private static JTokenType GetStringValueType(JTokenType? current)
{ {
if (current == null) if (current == null)
return JsonTokenType.String; return JTokenType.String;
switch (current.Value) switch (current.Value)
{ {
case JsonTokenType.Comment: case JTokenType.Comment:
case JsonTokenType.String: case JTokenType.String:
case JsonTokenType.Raw: case JTokenType.Raw:
return current.Value; return current.Value;
default: default:
return JsonTokenType.String; return JTokenType.String;
} }
} }
@@ -240,7 +240,7 @@ namespace Newtonsoft.Json.Linq
/// Gets the node type for this <see cref="JToken"/>. /// Gets the node type for this <see cref="JToken"/>.
/// </summary> /// </summary>
/// <value>The type.</value> /// <value>The type.</value>
public override JsonTokenType Type public override JTokenType Type
{ {
get { return _valueType; } get { return _valueType; }
} }
@@ -284,22 +284,22 @@ namespace Newtonsoft.Json.Linq
{ {
switch (_valueType) switch (_valueType)
{ {
case JsonTokenType.Comment: case JTokenType.Comment:
writer.WriteComment(_value.ToString()); writer.WriteComment(_value.ToString());
break; break;
case JsonTokenType.Integer: case JTokenType.Integer:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToInt64(v, CultureInfo.InvariantCulture)), _value); WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToInt64(v, CultureInfo.InvariantCulture)), _value);
break; break;
case JsonTokenType.Float: case JTokenType.Float:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToDouble(v, CultureInfo.InvariantCulture)), _value); WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToDouble(v, CultureInfo.InvariantCulture)), _value);
break; break;
case JsonTokenType.String: case JTokenType.String:
WriteConvertableValue(writer, converters, v => writer.WriteValue(v.ToString()), _value); WriteConvertableValue(writer, converters, v => writer.WriteValue(v.ToString()), _value);
break; break;
case JsonTokenType.Boolean: case JTokenType.Boolean:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToBoolean(v, CultureInfo.InvariantCulture)), _value); WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToBoolean(v, CultureInfo.InvariantCulture)), _value);
break; break;
case JsonTokenType.Date: case JTokenType.Date:
WriteConvertableValue(writer, converters, v => WriteConvertableValue(writer, converters, v =>
{ {
if (v is DateTimeOffset) if (v is DateTimeOffset)
@@ -308,13 +308,13 @@ namespace Newtonsoft.Json.Linq
writer.WriteValue(Convert.ToDateTime(v, CultureInfo.InvariantCulture)); writer.WriteValue(Convert.ToDateTime(v, CultureInfo.InvariantCulture));
}, _value); }, _value);
break; break;
case JsonTokenType.Raw: case JTokenType.Raw:
writer.WriteRawValue(_value.ToString()); writer.WriteRawValue(_value.ToString());
break; break;
case JsonTokenType.Null: case JTokenType.Null:
writer.WriteNull(); writer.WriteNull();
break; break;
case JsonTokenType.Undefined: case JTokenType.Undefined:
writer.WriteUndefined(); writer.WriteUndefined();
break; break;
default: default:
@@ -68,6 +68,9 @@
<Compile Include="JsonValidatingReader.cs" /> <Compile Include="JsonValidatingReader.cs" />
<Compile Include="Linq\IJEnumerable.cs" /> <Compile Include="Linq\IJEnumerable.cs" />
<Compile Include="Linq\JTokenEqualityComparer.cs" /> <Compile Include="Linq\JTokenEqualityComparer.cs" />
<Compile Include="Linq\JTokenReader.cs" />
<Compile Include="Linq\JTokenType.cs" />
<Compile Include="Linq\JTokenWriter.cs" />
<Compile Include="MemberSerialization.cs" /> <Compile Include="MemberSerialization.cs" />
<Compile Include="ObjectCreationHandling.cs" /> <Compile Include="ObjectCreationHandling.cs" />
<Compile Include="Converters\IsoDateTimeConverter.cs" /> <Compile Include="Converters\IsoDateTimeConverter.cs" />
@@ -94,11 +97,8 @@
<Compile Include="Linq\JEnumerable.cs" /> <Compile Include="Linq\JEnumerable.cs" />
<Compile Include="Linq\JObject.cs" /> <Compile Include="Linq\JObject.cs" />
<Compile Include="Linq\JArray.cs" /> <Compile Include="Linq\JArray.cs" />
<Compile Include="Linq\JsonTokenReader.cs" />
<Compile Include="Linq\JsonTokenWriter.cs" />
<Compile Include="Linq\JToken.cs" /> <Compile Include="Linq\JToken.cs" />
<Compile Include="Linq\JProperty.cs" /> <Compile Include="Linq\JProperty.cs" />
<Compile Include="Linq\JsonTokenType.cs" />
<Compile Include="Linq\JValue.cs" /> <Compile Include="Linq\JValue.cs" />
<Compile Include="Schema\Extensions.cs" /> <Compile Include="Schema\Extensions.cs" />
<Compile Include="Schema\JsonSchemaException.cs" /> <Compile Include="Schema\JsonSchemaException.cs" />
@@ -87,11 +87,11 @@
<Compile Include="Linq\JEnumerable.cs" /> <Compile Include="Linq\JEnumerable.cs" />
<Compile Include="Linq\JObject.cs" /> <Compile Include="Linq\JObject.cs" />
<Compile Include="Linq\JProperty.cs" /> <Compile Include="Linq\JProperty.cs" />
<Compile Include="Linq\JsonTokenReader.cs" />
<Compile Include="Linq\JsonTokenType.cs" />
<Compile Include="Linq\JsonTokenWriter.cs" />
<Compile Include="Linq\JToken.cs" /> <Compile Include="Linq\JToken.cs" />
<Compile Include="Linq\JTokenEqualityComparer.cs" /> <Compile Include="Linq\JTokenEqualityComparer.cs" />
<Compile Include="Linq\JTokenReader.cs" />
<Compile Include="Linq\JTokenType.cs" />
<Compile Include="Linq\JTokenWriter.cs" />
<Compile Include="Linq\JValue.cs" /> <Compile Include="Linq\JValue.cs" />
<Compile Include="MemberSerialization.cs" /> <Compile Include="MemberSerialization.cs" />
<Compile Include="MissingMemberHandling.cs" /> <Compile Include="MissingMemberHandling.cs" />
+3 -3
View File
@@ -115,11 +115,11 @@
<Compile Include="Linq\JEnumerable.cs" /> <Compile Include="Linq\JEnumerable.cs" />
<Compile Include="Linq\JObject.cs" /> <Compile Include="Linq\JObject.cs" />
<Compile Include="Linq\JArray.cs" /> <Compile Include="Linq\JArray.cs" />
<Compile Include="Linq\JsonTokenReader.cs" /> <Compile Include="Linq\JTokenReader.cs" />
<Compile Include="Linq\JsonTokenWriter.cs" /> <Compile Include="Linq\JTokenWriter.cs" />
<Compile Include="Linq\JToken.cs" /> <Compile Include="Linq\JToken.cs" />
<Compile Include="Linq\JProperty.cs" /> <Compile Include="Linq\JProperty.cs" />
<Compile Include="Linq\JsonTokenType.cs" /> <Compile Include="Linq\JTokenType.cs" />
<Compile Include="Linq\JValue.cs" /> <Compile Include="Linq\JValue.cs" />
<Compile Include="Schema\Extensions.cs" /> <Compile Include="Schema\Extensions.cs" />
<Compile Include="Schema\JsonSchemaException.cs" /> <Compile Include="Schema\JsonSchemaException.cs" />