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