Fix JTokenWriter when writing comment to an object (#2493)

This commit is contained in:
James Newton-King
2021-03-11 21:53:58 +13:00
committed by GitHub
parent 583eb12015
commit 1745d7c14e
6 changed files with 112 additions and 21 deletions
+3 -3
View File
@@ -241,12 +241,12 @@ namespace Newtonsoft.Json.Linq
return _content.IndexOf(item);
}
internal override void InsertItem(int index, JToken? item, bool skipParentCheck)
internal override bool InsertItem(int index, JToken? item, bool skipParentCheck)
{
// don't add comments to JProperty
if (item != null && item.Type == JTokenType.Comment)
{
return;
return false;
}
if (Value != null)
@@ -254,7 +254,7 @@ namespace Newtonsoft.Json.Linq
throw new JsonException("{0} cannot have multiple values.".FormatWith(CultureInfo.InvariantCulture, typeof(JProperty)));
}
base.InsertItem(0, item, false);
return base.InsertItem(0, item, false);
}
internal override bool ContainsItem(JToken? item)