-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.
/// </summary>
/// <value>The value of the Oid.</value>
public byte[] Value { get; private set; }
public byte[] Value { get; }
/// <summary>
/// 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 (value is BigInteger)
{
InternalWriteValue(JsonToken.Integer);
SetWriteState(JsonToken.Integer, null);
AddToken(new BsonBinary(((BigInteger)value).ToByteArray(), BsonBinaryType.Binary));
}
else
@@ -516,8 +516,7 @@ namespace Newtonsoft.Json.Bson
}
// hack to update the writer state
UpdateScopeWithFinishedValue();
AutoComplete(JsonToken.Undefined);
SetWriteState(JsonToken.Undefined, null);
AddValue(value, BsonType.Oid);
}
@@ -531,8 +530,7 @@ namespace Newtonsoft.Json.Bson
ValidationUtils.ArgumentNotNull(pattern, nameof(pattern));
// hack to update the writer state
UpdateScopeWithFinishedValue();
AutoComplete(JsonToken.Undefined);
SetWriteState(JsonToken.Undefined, null);
AddToken(new BsonRegex(pattern, options));
}
}
@@ -435,7 +435,7 @@ namespace Newtonsoft.Json.Converters
#if HAVE_XLINQ
internal class XDeclarationWrapper : XObjectWrapper, IXmlDeclaration
{
internal XDeclaration Declaration { get; private set; }
internal XDeclaration Declaration { get; }
public XDeclarationWrapper(XDeclaration declaration)
: 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"/>.
/// If <c>null</c>, the default constructor is used.
/// </summary>
public object[] ConverterParameters { get; private set; }
public object[] ConverterParameters { get; }
/// <summary>
/// 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.
/// </summary>
/// <value>The line number indicating where the error occurred.</value>
public int LineNumber { get; private set; }
public int LineNumber { get; }
/// <summary>
/// Gets the line position indicating where the error occurred.
/// </summary>
/// <value>The line position indicating where the error occurred.</value>
public int LinePosition { get; private set; }
public int LinePosition { get; }
/// <summary>
/// Gets the path to the JSON where the error occurred.
/// </summary>
/// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; }
public string Path { get; }
/// <summary>
/// Initializes a new instance of the <see cref="JsonReaderException"/> class.
@@ -98,7 +98,16 @@ namespace Newtonsoft.Json
}
#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)
{
Path = path;
@@ -133,7 +142,7 @@ namespace Newtonsoft.Json
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 int ArrayItemCount { get; set; }
public bool IsUniqueArray { get; set; }
public IList<JToken> UniqueArrayItems { get; set; }
public bool IsUniqueArray { get; }
public IList<JToken> UniqueArrayItems { get; }
public JTokenWriter CurrentItemWriter { get; set; }
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.
/// </summary>
/// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; }
public string Path { get; }
/// <summary>
/// Initializes a new instance of the <see cref="JsonWriterException"/> class.
@@ -86,7 +86,14 @@ namespace Newtonsoft.Json
}
#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)
{
Path = path;
@@ -101,7 +108,7 @@ namespace Newtonsoft.Json
{
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
{
private readonly string _expression;
public List<PathFilter> Filters { get; private set; }
public List<PathFilter> Filters { get; }
private int _currentIndex;
@@ -46,19 +46,19 @@ namespace Newtonsoft.Json.Schema
/// Gets the line number indicating where the error occurred.
/// </summary>
/// <value>The line number indicating where the error occurred.</value>
public int LineNumber { get; private set; }
public int LineNumber { get; }
/// <summary>
/// Gets the line position indicating where the error occurred.
/// </summary>
/// <value>The line position indicating where the error occurred.</value>
public int LinePosition { get; private set; }
public int LinePosition { get; }
/// <summary>
/// Gets the path to the JSON where the error occurred.
/// </summary>
/// <value>The path to the JSON where the error occurred.</value>
public string Path { get; private set; }
public string Path { get; }
/// <summary>
/// Initializes a new instance of the <see cref="JsonSchemaException"/> class.
@@ -77,8 +77,8 @@ namespace Newtonsoft.Json.Schema
private class TypeSchema
{
public Type Type { get; private set; }
public JsonSchema Schema { get; private set; }
public Type Type { get; }
public JsonSchema Schema { get; }
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.")]
internal class JsonSchemaNode
{
public string Id { get; private set; }
public ReadOnlyCollection<JsonSchema> Schemas { get; private set; }
public Dictionary<string, JsonSchemaNode> Properties { get; private set; }
public Dictionary<string, JsonSchemaNode> PatternProperties { get; private set; }
public List<JsonSchemaNode> Items { get; private set; }
public string Id { get; }
public ReadOnlyCollection<JsonSchema> Schemas { get; }
public Dictionary<string, JsonSchemaNode> Properties { get; }
public Dictionary<string, JsonSchemaNode> PatternProperties { get; }
public List<JsonSchemaNode> Items { get; }
public JsonSchemaNode AdditionalProperties { get; set; }
public JsonSchemaNode AdditionalItems { get; set; }
@@ -46,25 +46,25 @@ namespace Newtonsoft.Json.Serialization
/// Gets the error.
/// </summary>
/// <value>The error.</value>
public Exception Error { get; private set; }
public Exception Error { get; }
/// <summary>
/// Gets the original object that caused the error.
/// </summary>
/// <value>The original object that caused the error.</value>
public object OriginalObject { get; private set; }
public object OriginalObject { get; }
/// <summary>
/// Gets the member that caused the error.
/// </summary>
/// <value>The member that caused the error.</value>
public object Member { get; private set; }
public object Member { get; }
/// <summary>
/// Gets the path of the JSON location where the error occurred.
/// </summary>
/// <value>The path of the JSON location where the error occurred.</value>
public string Path { get; private set; }
public string Path { get; }
/// <summary>
/// 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.
/// </summary>
/// <value>The current object the error event is being raised against.</value>
public object CurrentObject { get; private set; }
public object CurrentObject { get; }
/// <summary>
/// Gets the error context.
/// </summary>
/// <value>The error context.</value>
public ErrorContext ErrorContext { get; private set; }
public ErrorContext ErrorContext { get; }
/// <summary>
/// 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.
/// </summary>
/// <value>The <see cref="System.Type"/> of the collection items.</value>
public Type CollectionItemType { get; private set; }
public Type CollectionItemType { get; }
/// <summary>
/// Gets a value indicating whether the collection type is a multidimensional array.
/// </summary>
/// <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;
@@ -63,8 +63,8 @@ namespace Newtonsoft.Json.Serialization
private ObjectConstructor<object> _genericWrapperCreator;
private Func<object> _genericTemporaryCollectionCreator;
internal bool IsArray { get; private set; }
internal bool ShouldCreateWrapper { get; private set; }
internal bool IsArray { get; }
internal bool ShouldCreateWrapper { get; }
internal bool CanDeserialize { get; private set; }
private readonly ConstructorInfo _parameterizedConstructor;
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the underlying type for the contract.
/// </summary>
/// <value>The underlying type for the contract.</value>
public Type UnderlyingType { get; private set; }
public Type UnderlyingType { get; }
/// <summary>
/// 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.
/// </summary>
/// <value>The <see cref="System.Type"/> of the dictionary keys.</value>
public Type DictionaryKeyType { get; private set; }
public Type DictionaryKeyType { get; }
/// <summary>
/// Gets the <see cref="System.Type"/> of the dictionary values.
/// </summary>
/// <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; }
@@ -68,7 +68,7 @@ namespace Newtonsoft.Json.Serialization
private Func<object> _genericTemporaryDictionaryCreator;
internal bool ShouldCreateWrapper { get; private set; }
internal bool ShouldCreateWrapper { get; }
private readonly ConstructorInfo _parameterizedConstructor;
@@ -43,7 +43,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the object's properties.
/// </summary>
/// <value>The object's properties.</value>
public JsonPropertyCollection Properties { get; private set; }
public JsonPropertyCollection Properties { get; }
/// <summary>
/// Gets or sets the property name resolver.
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization
/// Gets the object's properties.
/// </summary>
/// <value>The object's properties.</value>
public JsonPropertyCollection Properties { get; private set; }
public JsonPropertyCollection Properties { get; }
/// <summary>
/// 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
{
public ObjectConstructor<object> Creator { get; private set; }
public IDictionary<string, ReflectionMember> Members { get; private set; }
public ObjectConstructor<object> Creator { get; }
public IDictionary<string, ReflectionMember> Members { get; }
public ReflectionObject()
private ReflectionObject(ObjectConstructor<object> creator)
{
Members = new Dictionary<string, ReflectionMember>();
Creator = creator;
}
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)
{
ReflectionObject d = new ReflectionObject();
ReflectionDelegateFactory delegateFactory = JsonTypeReflector.ReflectionDelegateFactory;
ObjectConstructor<object> creatorConstructor = null;
if (creator != null)
{
d.Creator = delegateFactory.CreateParameterizedConstructor(creator);
creatorConstructor = delegateFactory.CreateParameterizedConstructor(creator);
}
else
{
@@ -93,10 +93,12 @@ namespace Newtonsoft.Json.Utilities
{
Func<object> ctor = delegateFactory.CreateDefaultConstructor<object>(t);
d.Creator = args => ctor();
creatorConstructor = args => ctor();
}
}
ReflectionObject d = new ReflectionObject(creatorConstructor);
foreach (string memberName in memberNames)
{
MemberInfo[] members = t.GetMember(memberName, BindingFlags.Instance | BindingFlags.Public);