-Additional JToken line info settings fixes

This commit is contained in:
James Newton-King
2017-03-23 21:04:04 +13:00
parent fa3b038acf
commit 68533cdc19
2 changed files with 28 additions and 2 deletions
+19 -2
View File
@@ -586,15 +586,32 @@ Parameter name: index");
{
string json = "[1,2,3]";
JArray a = JArray.Parse(json, new JsonLoadSettings
JArray a = JArray.Parse(json, new JsonLoadSettings());
Assert.AreEqual(true, ((IJsonLineInfo)a).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[0]).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[1]).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[2]).HasLineInfo());
a = JArray.Parse(json, new JsonLoadSettings
{
LineInfoHandling = LineInfoHandling.Load
LineInfoHandling = LineInfoHandling.Ignore
});
Assert.AreEqual(false, ((IJsonLineInfo)a).HasLineInfo());
Assert.AreEqual(false, ((IJsonLineInfo)a[0]).HasLineInfo());
Assert.AreEqual(false, ((IJsonLineInfo)a[1]).HasLineInfo());
Assert.AreEqual(false, ((IJsonLineInfo)a[2]).HasLineInfo());
a = JArray.Parse(json, new JsonLoadSettings
{
LineInfoHandling = LineInfoHandling.Load
});
Assert.AreEqual(true, ((IJsonLineInfo)a).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[0]).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[1]).HasLineInfo());
Assert.AreEqual(true, ((IJsonLineInfo)a[2]).HasLineInfo());
}
}
}
@@ -10,6 +10,15 @@ namespace Newtonsoft.Json.Linq
private CommentHandling _commentHandling;
private LineInfoHandling _lineInfoHandling;
/// <summary>
/// Initializes a new instance of the <see cref="JsonLoadSettings"/> class.
/// </summary>
public JsonLoadSettings()
{
_lineInfoHandling = LineInfoHandling.Load;
_commentHandling = CommentHandling.Ignore;
}
/// <summary>
/// Gets or sets how JSON comments are handled when loading JSON.
/// </summary>