From f5684137177d088e9c41250e35788224270753a9 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 1 Mar 2014 18:39:21 +1300 Subject: [PATCH] -Clean up --- Src/Newtonsoft.Json/Bson/BsonReader.cs | 5 +++-- Src/Newtonsoft.Json/JsonReader.cs | 5 +++-- Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs | 3 ++- Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs | 2 -- Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs | 3 ++- .../Serialization/JsonSerializerInternalReader.cs | 8 ++++---- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Src/Newtonsoft.Json/Bson/BsonReader.cs b/Src/Newtonsoft.Json/Bson/BsonReader.cs index 2f9923e9..2a68d583 100644 --- a/Src/Newtonsoft.Json/Bson/BsonReader.cs +++ b/Src/Newtonsoft.Json/Bson/BsonReader.cs @@ -28,6 +28,7 @@ using System.Collections.Generic; using System.Globalization; using System.Text; using System.IO; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Utilities; using Newtonsoft.Json.Linq; @@ -356,7 +357,7 @@ namespace Newtonsoft.Json.Bson { case State.ObjectStart: { - SetToken(JsonToken.PropertyName, "$ref"); + SetToken(JsonToken.PropertyName, JsonTypeReflector.RefPropertyName); _bsonReaderState = BsonReaderState.ReferenceRef; return true; } @@ -381,7 +382,7 @@ namespace Newtonsoft.Json.Bson { if (_bsonReaderState == BsonReaderState.ReferenceRef) { - SetToken(JsonToken.PropertyName, "$id"); + SetToken(JsonToken.PropertyName, JsonTypeReflector.IdPropertyName); _bsonReaderState = BsonReaderState.ReferenceId; return true; } diff --git a/Src/Newtonsoft.Json/JsonReader.cs b/Src/Newtonsoft.Json/JsonReader.cs index 7a8db4ca..20a63879 100644 --- a/Src/Newtonsoft.Json/JsonReader.cs +++ b/Src/Newtonsoft.Json/JsonReader.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Globalization; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Utilities; #if NET20 using Newtonsoft.Json.Utilities.LinqBridge; @@ -760,13 +761,13 @@ namespace Newtonsoft.Json if (!ReadInternal()) throw JsonReaderException.Create(this, "Unexpected end when reading bytes."); - if (Value.ToString() == "$type") + if (Value.ToString() == JsonTypeReflector.TypePropertyName) { ReadInternal(); if (Value != null && Value.ToString().StartsWith("System.Byte[]")) { ReadInternal(); - if (Value.ToString() == "$value") + if (Value.ToString() == JsonTypeReflector.ValuePropertyName) { return true; } diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs index 8b150289..1688eb49 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs @@ -25,6 +25,7 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json.Serialization; #if NET20 using Newtonsoft.Json.Utilities.LinqBridge; #else @@ -194,7 +195,7 @@ namespace Newtonsoft.Json.Schema throw JsonException.Create(token, token.Path, "Expected object while parsing schema object, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type)); JToken referenceToken; - if (schemaObject.TryGetValue(JsonSchemaConstants.ReferencePropertyName, out referenceToken)) + if (schemaObject.TryGetValue(JsonTypeReflector.RefPropertyName, out referenceToken)) { JsonSchema deferredSchema = new JsonSchema(); deferredSchema.DeferredReference = (string)referenceToken; diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs index 692517ad..26b824dd 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaConstants.cs @@ -63,8 +63,6 @@ namespace Newtonsoft.Json.Schema public const string OptionValuePropertyName = "value"; public const string OptionLabelPropertyName = "label"; - public const string ReferencePropertyName = "$ref"; - public static readonly IDictionary JsonSchemaTypeMapping = new Dictionary { { "string", JsonSchemaType.String }, diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs index 2ca437cc..e5a817ba 100644 --- a/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs +++ b/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs @@ -25,6 +25,7 @@ using System.Collections.Generic; using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; using Newtonsoft.Json.Utilities; #if NET20 using Newtonsoft.Json.Utilities.LinqBridge; @@ -52,7 +53,7 @@ namespace Newtonsoft.Json.Schema if (schema.Id != null && _resolver.GetSchema(schema.Id) != null) { _writer.WriteStartObject(); - _writer.WritePropertyName(JsonSchemaConstants.ReferencePropertyName); + _writer.WritePropertyName(JsonTypeReflector.RefPropertyName); _writer.WriteValue(schema.Id); _writer.WriteEndObject(); } diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index d791b156..d093800d 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -1948,10 +1948,10 @@ To fix this error either change the environment to be fully trusted, change the { switch (memberName) { - case "$type": - case "$id": - case "$ref": - case "$values": + case JsonTypeReflector.IdPropertyName: + case JsonTypeReflector.RefPropertyName: + case JsonTypeReflector.TypePropertyName: + case JsonTypeReflector.ArrayValuesPropertyName: reader.Skip(); return true; }