-Added JsonReaderException ctor with path, line number, line position

-Added JsonWriterException ctor with path
This commit is contained in:
James Newton-King
2017-02-18 21:49:35 +13:00
parent 7a7027a779
commit b65807bbd2
19 changed files with 68 additions and 52 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ namespace Newtonsoft.Json.Bson
/// Gets or sets the value of the Oid. /// Gets or sets the value of the Oid.
/// </summary> /// </summary>
/// <value>The value of the Oid.</value> /// <value>The value of the Oid.</value>
public byte[] Value { get; private set; } public byte[] Value { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="BsonObjectId"/> class. /// Initializes a new instance of the <see cref="BsonObjectId"/> class.
+3 -5
View File
@@ -238,7 +238,7 @@ namespace Newtonsoft.Json.Bson
#if HAVE_BIG_INTEGER #if HAVE_BIG_INTEGER
if (value is BigInteger) if (value is BigInteger)
{ {
InternalWriteValue(JsonToken.Integer); SetWriteState(JsonToken.Integer, null);
AddToken(new BsonBinary(((BigInteger)value).ToByteArray(), BsonBinaryType.Binary)); AddToken(new BsonBinary(((BigInteger)value).ToByteArray(), BsonBinaryType.Binary));
} }
else else
@@ -516,8 +516,7 @@ namespace Newtonsoft.Json.Bson
} }
// hack to update the writer state // hack to update the writer state
UpdateScopeWithFinishedValue(); SetWriteState(JsonToken.Undefined, null);
AutoComplete(JsonToken.Undefined);
AddValue(value, BsonType.Oid); AddValue(value, BsonType.Oid);
} }
@@ -531,8 +530,7 @@ namespace Newtonsoft.Json.Bson
ValidationUtils.ArgumentNotNull(pattern, nameof(pattern)); ValidationUtils.ArgumentNotNull(pattern, nameof(pattern));
// hack to update the writer state // hack to update the writer state
UpdateScopeWithFinishedValue(); SetWriteState(JsonToken.Undefined, null);
AutoComplete(JsonToken.Undefined);
AddToken(new BsonRegex(pattern, options)); AddToken(new BsonRegex(pattern, options));
} }
} }
@@ -435,7 +435,7 @@ namespace Newtonsoft.Json.Converters
#if HAVE_XLINQ #if HAVE_XLINQ
internal class XDeclarationWrapper : XObjectWrapper, IXmlDeclaration internal class XDeclarationWrapper : XObjectWrapper, IXmlDeclaration
{ {
internal XDeclaration Declaration { get; private set; } internal XDeclaration Declaration { get; }
public XDeclarationWrapper(XDeclaration declaration) public XDeclarationWrapper(XDeclaration declaration)
: base(null) : base(null)
@@ -50,7 +50,7 @@ namespace Newtonsoft.Json
/// The parameter list to use when constructing the <see cref="JsonConverter"/> described by <see cref="ConverterType"/>. /// The parameter list to use when constructing the <see cref="JsonConverter"/> described by <see cref="ConverterType"/>.
/// If <c>null</c>, the default constructor is used. /// If <c>null</c>, the default constructor is used.
/// </summary> /// </summary>
public object[] ConverterParameters { get; private set; } public object[] ConverterParameters { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonConverterAttribute"/> class. /// Initializes a new instance of the <see cref="JsonConverterAttribute"/> class.
+14 -5
View File
@@ -42,19 +42,19 @@ namespace Newtonsoft.Json
/// Gets the line number indicating where the error occurred. /// Gets the line number indicating where the error occurred.
/// </summary> /// </summary>
/// <value>The line number indicating where the error occurred.</value> /// <value>The line number indicating where the error occurred.</value>
public int LineNumber { get; private set; } public int LineNumber { get; }
/// <summary> /// <summary>
/// Gets the line position indicating where the error occurred. /// Gets the line position indicating where the error occurred.
/// </summary> /// </summary>
/// <value>The line position indicating where the error occurred.</value> /// <value>The line position indicating where the error occurred.</value>
public int LinePosition { get; private set; } public int LinePosition { get; }
/// <summary> /// <summary>
/// Gets the path to the JSON where the error occurred. /// Gets the path to the JSON where the error occurred.
/// </summary> /// </summary>
/// <value>The path to the JSON where the error occurred.</value> /// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; } public string Path { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonReaderException"/> class. /// Initializes a new instance of the <see cref="JsonReaderException"/> class.
@@ -98,7 +98,16 @@ namespace Newtonsoft.Json
} }
#endif #endif
internal JsonReaderException(string message, Exception innerException, string path, int lineNumber, int linePosition) /// <summary>
/// Initializes a new instance of the <see cref="JsonReaderException"/> class
/// with a specified error message, JSON path, line number, line position, and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="path">The path to the JSON where the error occurred.</param>
/// <param name="lineNumber">The line number indicating where the error occurred.</param>
/// <param name="linePosition">The line position indicating where the error occurred.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or <c>null</c> if no inner exception is specified.</param>
public JsonReaderException(string message, string path, int lineNumber, int linePosition, Exception innerException)
: base(message, innerException) : base(message, innerException)
{ {
Path = path; Path = path;
@@ -133,7 +142,7 @@ namespace Newtonsoft.Json
linePosition = 0; linePosition = 0;
} }
return new JsonReaderException(message, ex, path, lineNumber, linePosition); return new JsonReaderException(message, path, lineNumber, linePosition, ex);
} }
} }
} }
+2 -2
View File
@@ -62,8 +62,8 @@ namespace Newtonsoft.Json
public string CurrentPropertyName { get; set; } public string CurrentPropertyName { get; set; }
public int ArrayItemCount { get; set; } public int ArrayItemCount { get; set; }
public bool IsUniqueArray { get; set; } public bool IsUniqueArray { get; }
public IList<JToken> UniqueArrayItems { get; set; } public IList<JToken> UniqueArrayItems { get; }
public JTokenWriter CurrentItemWriter { get; set; } public JTokenWriter CurrentItemWriter { get; set; }
public IList<JsonSchemaModel> Schemas public IList<JsonSchemaModel> Schemas
+10 -3
View File
@@ -42,7 +42,7 @@ namespace Newtonsoft.Json
/// Gets the path to the JSON where the error occurred. /// Gets the path to the JSON where the error occurred.
/// </summary> /// </summary>
/// <value>The path to the JSON where the error occurred.</value> /// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; } public string Path { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonWriterException"/> class. /// Initializes a new instance of the <see cref="JsonWriterException"/> class.
@@ -86,7 +86,14 @@ namespace Newtonsoft.Json
} }
#endif #endif
internal JsonWriterException(string message, Exception innerException, string path) /// <summary>
/// Initializes a new instance of the <see cref="JsonWriterException"/> class
/// with a specified error message, JSON path and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="path">The path to the JSON where the error occurred.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or <c>null</c> if no inner exception is specified.</param>
public JsonWriterException(string message, string path, Exception innerException)
: base(message, innerException) : base(message, innerException)
{ {
Path = path; Path = path;
@@ -101,7 +108,7 @@ namespace Newtonsoft.Json
{ {
message = JsonPosition.FormatMessage(null, path, message); message = JsonPosition.FormatMessage(null, path, message);
return new JsonWriterException(message, ex, path); return new JsonWriterException(message, path, ex);
} }
} }
} }
+1 -1
View File
@@ -34,7 +34,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
internal class JPath internal class JPath
{ {
private readonly string _expression; private readonly string _expression;
public List<PathFilter> Filters { get; private set; } public List<PathFilter> Filters { get; }
private int _currentIndex; private int _currentIndex;
@@ -46,19 +46,19 @@ namespace Newtonsoft.Json.Schema
/// Gets the line number indicating where the error occurred. /// Gets the line number indicating where the error occurred.
/// </summary> /// </summary>
/// <value>The line number indicating where the error occurred.</value> /// <value>The line number indicating where the error occurred.</value>
public int LineNumber { get; private set; } public int LineNumber { get; }
/// <summary> /// <summary>
/// Gets the line position indicating where the error occurred. /// Gets the line position indicating where the error occurred.
/// </summary> /// </summary>
/// <value>The line position indicating where the error occurred.</value> /// <value>The line position indicating where the error occurred.</value>
public int LinePosition { get; private set; } public int LinePosition { get; }
/// <summary> /// <summary>
/// Gets the path to the JSON where the error occurred. /// Gets the path to the JSON where the error occurred.
/// </summary> /// </summary>
/// <value>The path to the JSON where the error occurred.</value> /// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; } public string Path { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonSchemaException"/> class. /// Initializes a new instance of the <see cref="JsonSchemaException"/> class.
@@ -77,8 +77,8 @@ namespace Newtonsoft.Json.Schema
private class TypeSchema private class TypeSchema
{ {
public Type Type { get; private set; } public Type Type { get; }
public JsonSchema Schema { get; private set; } public JsonSchema Schema { get; }
public TypeSchema(Type type, JsonSchema schema) public TypeSchema(Type type, JsonSchema schema)
{ {
+5 -5
View File
@@ -38,11 +38,11 @@ namespace Newtonsoft.Json.Schema
[Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")] [Obsolete("JSON Schema validation has been moved to its own package. See http://www.newtonsoft.com/jsonschema for more details.")]
internal class JsonSchemaNode internal class JsonSchemaNode
{ {
public string Id { get; private set; } public string Id { get; }
public ReadOnlyCollection<JsonSchema> Schemas { get; private set; } public ReadOnlyCollection<JsonSchema> Schemas { get; }
public Dictionary<string, JsonSchemaNode> Properties { get; private set; } public Dictionary<string, JsonSchemaNode> Properties { get; }
public Dictionary<string, JsonSchemaNode> PatternProperties { get; private set; } public Dictionary<string, JsonSchemaNode> PatternProperties { get; }
public List<JsonSchemaNode> Items { get; private set; } public List<JsonSchemaNode> Items { get; }
public JsonSchemaNode AdditionalProperties { get; set; } public JsonSchemaNode AdditionalProperties { get; set; }
public JsonSchemaNode AdditionalItems { get; set; } public JsonSchemaNode AdditionalItems { get; set; }
@@ -46,25 +46,25 @@ namespace Newtonsoft.Json.Serialization
/// Gets the error. /// Gets the error.
/// </summary> /// </summary>
/// <value>The error.</value> /// <value>The error.</value>
public Exception Error { get; private set; } public Exception Error { get; }
/// <summary> /// <summary>
/// Gets the original object that caused the error. /// Gets the original object that caused the error.
/// </summary> /// </summary>
/// <value>The original object that caused the error.</value> /// <value>The original object that caused the error.</value>
public object OriginalObject { get; private set; } public object OriginalObject { get; }
/// <summary> /// <summary>
/// Gets the member that caused the error. /// Gets the member that caused the error.
/// </summary> /// </summary>
/// <value>The member that caused the error.</value> /// <value>The member that caused the error.</value>
public object Member { get; private set; } public object Member { get; }
/// <summary> /// <summary>
/// Gets the path of the JSON location where the error occurred. /// Gets the path of the JSON location where the error occurred.
/// </summary> /// </summary>
/// <value>The path of the JSON location where the error occurred.</value> /// <value>The path of the JSON location where the error occurred.</value>
public string Path { get; private set; } public string Path { get; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this <see cref="ErrorContext"/> is handled. /// Gets or sets a value indicating whether this <see cref="ErrorContext"/> is handled.
@@ -36,13 +36,13 @@ namespace Newtonsoft.Json.Serialization
/// Gets the current object the error event is being raised against. /// Gets the current object the error event is being raised against.
/// </summary> /// </summary>
/// <value>The current object the error event is being raised against.</value> /// <value>The current object the error event is being raised against.</value>
public object CurrentObject { get; private set; } public object CurrentObject { get; }
/// <summary> /// <summary>
/// Gets the error context. /// Gets the error context.
/// </summary> /// </summary>
/// <value>The error context.</value> /// <value>The error context.</value>
public ErrorContext ErrorContext { get; private set; } public ErrorContext ErrorContext { get; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ErrorEventArgs"/> class. /// Initializes a new instance of the <see cref="ErrorEventArgs"/> class.
@@ -49,13 +49,13 @@ namespace Newtonsoft.Json.Serialization
/// Gets the <see cref="System.Type"/> of the collection items. /// Gets the <see cref="System.Type"/> of the collection items.
/// </summary> /// </summary>
/// <value>The <see cref="System.Type"/> of the collection items.</value> /// <value>The <see cref="System.Type"/> of the collection items.</value>
public Type CollectionItemType { get; private set; } public Type CollectionItemType { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether the collection type is a multidimensional array. /// Gets a value indicating whether the collection type is a multidimensional array.
/// </summary> /// </summary>
/// <value><c>true</c> if the collection type is a multidimensional array; otherwise, <c>false</c>.</value> /// <value><c>true</c> if the collection type is a multidimensional array; otherwise, <c>false</c>.</value>
public bool IsMultidimensionalArray { get; private set; } public bool IsMultidimensionalArray { get; }
private readonly Type _genericCollectionDefinitionType; private readonly Type _genericCollectionDefinitionType;
@@ -63,8 +63,8 @@ namespace Newtonsoft.Json.Serialization
private ObjectConstructor<object> _genericWrapperCreator; private ObjectConstructor<object> _genericWrapperCreator;
private Func<object> _genericTemporaryCollectionCreator; private Func<object> _genericTemporaryCollectionCreator;
internal bool IsArray { get; private set; } internal bool IsArray { get; }
internal bool ShouldCreateWrapper { get; private set; } internal bool ShouldCreateWrapper { get; }
internal bool CanDeserialize { get; private set; } internal bool CanDeserialize { get; private set; }
private readonly ConstructorInfo _parameterizedConstructor; private readonly ConstructorInfo _parameterizedConstructor;
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the underlying type for the contract. /// Gets the underlying type for the contract.
/// </summary> /// </summary>
/// <value>The underlying type for the contract.</value> /// <value>The underlying type for the contract.</value>
public Type UnderlyingType { get; private set; } public Type UnderlyingType { get; }
/// <summary> /// <summary>
/// Gets or sets the type created during deserialization. /// Gets or sets the type created during deserialization.
@@ -51,13 +51,13 @@ namespace Newtonsoft.Json.Serialization
/// Gets the <see cref="System.Type"/> of the dictionary keys. /// Gets the <see cref="System.Type"/> of the dictionary keys.
/// </summary> /// </summary>
/// <value>The <see cref="System.Type"/> of the dictionary keys.</value> /// <value>The <see cref="System.Type"/> of the dictionary keys.</value>
public Type DictionaryKeyType { get; private set; } public Type DictionaryKeyType { get; }
/// <summary> /// <summary>
/// Gets the <see cref="System.Type"/> of the dictionary values. /// Gets the <see cref="System.Type"/> of the dictionary values.
/// </summary> /// </summary>
/// <value>The <see cref="System.Type"/> of the dictionary values.</value> /// <value>The <see cref="System.Type"/> of the dictionary values.</value>
public Type DictionaryValueType { get; private set; } public Type DictionaryValueType { get; }
internal JsonContract KeyContract { get; set; } internal JsonContract KeyContract { get; set; }
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Serialization
private Func<object> _genericTemporaryDictionaryCreator; private Func<object> _genericTemporaryDictionaryCreator;
internal bool ShouldCreateWrapper { get; private set; } internal bool ShouldCreateWrapper { get; }
private readonly ConstructorInfo _parameterizedConstructor; private readonly ConstructorInfo _parameterizedConstructor;
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the object's properties. /// Gets the object's properties.
/// </summary> /// </summary>
/// <value>The object's properties.</value> /// <value>The object's properties.</value>
public JsonPropertyCollection Properties { get; private set; } public JsonPropertyCollection Properties { get; }
/// <summary> /// <summary>
/// Gets or sets the property name resolver. /// Gets or sets the property name resolver.
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the object's properties. /// Gets the object's properties.
/// </summary> /// </summary>
/// <value>The object's properties.</value> /// <value>The object's properties.</value>
public JsonPropertyCollection Properties { get; private set; } public JsonPropertyCollection Properties { get; }
/// <summary> /// <summary>
/// Gets a collection of <see cref="JsonProperty"/> instances that define the parameters used with <see cref="JsonObjectContract.OverrideCreator"/>. /// Gets a collection of <see cref="JsonProperty"/> instances that define the parameters used with <see cref="JsonObjectContract.OverrideCreator"/>.
@@ -47,12 +47,13 @@ namespace Newtonsoft.Json.Utilities
internal class ReflectionObject internal class ReflectionObject
{ {
public ObjectConstructor<object> Creator { get; private set; } public ObjectConstructor<object> Creator { get; }
public IDictionary<string, ReflectionMember> Members { get; private set; } public IDictionary<string, ReflectionMember> Members { get; }
public ReflectionObject() private ReflectionObject(ObjectConstructor<object> creator)
{ {
Members = new Dictionary<string, ReflectionMember>(); Members = new Dictionary<string, ReflectionMember>();
Creator = creator;
} }
public object GetValue(object target, string member) public object GetValue(object target, string member)
@@ -79,13 +80,12 @@ namespace Newtonsoft.Json.Utilities
public static ReflectionObject Create(Type t, MethodBase creator, params string[] memberNames) public static ReflectionObject Create(Type t, MethodBase creator, params string[] memberNames)
{ {
ReflectionObject d = new ReflectionObject();
ReflectionDelegateFactory delegateFactory = JsonTypeReflector.ReflectionDelegateFactory; ReflectionDelegateFactory delegateFactory = JsonTypeReflector.ReflectionDelegateFactory;
ObjectConstructor<object> creatorConstructor = null;
if (creator != null) if (creator != null)
{ {
d.Creator = delegateFactory.CreateParameterizedConstructor(creator); creatorConstructor = delegateFactory.CreateParameterizedConstructor(creator);
} }
else else
{ {
@@ -93,10 +93,12 @@ namespace Newtonsoft.Json.Utilities
{ {
Func<object> ctor = delegateFactory.CreateDefaultConstructor<object>(t); Func<object> ctor = delegateFactory.CreateDefaultConstructor<object>(t);
d.Creator = args => ctor(); creatorConstructor = args => ctor();
} }
} }
ReflectionObject d = new ReflectionObject(creatorConstructor);
foreach (string memberName in memberNames) foreach (string memberName in memberNames)
{ {
MemberInfo[] members = t.GetMember(memberName, BindingFlags.Instance | BindingFlags.Public); MemberInfo[] members = t.GetMember(memberName, BindingFlags.Instance | BindingFlags.Public);