From a9c7d60d2255d32f8e328f68485249a505942858 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 23 Nov 2015 20:31:28 +1300 Subject: [PATCH] -Improved JArray bad indexer message --- Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs | 2 +- Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs | 2 +- Src/Newtonsoft.Json/Linq/JArray.cs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs index 2746a738..90e31f31 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JArrayTests.cs @@ -471,7 +471,7 @@ Parameter name: index"); { JArray a = new JArray(); a["badvalue"] = new JValue(3); - }, @"Set JArray values with invalid key value: ""badvalue"". Array position index expected."); + }, @"Set JArray values with invalid key value: ""badvalue"". Int32 array index expected."); } [Test] diff --git a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs index f2934bf3..d2a86f1c 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs @@ -925,7 +925,7 @@ keyword such as type of business."" { JArray a = new JArray(); Assert.AreEqual(null, a["purple"]); - }, @"Accessed JArray values with invalid key value: ""purple"". Array position index expected."); + }, @"Accessed JArray values with invalid key value: ""purple"". Int32 array index expected."); } [Test] diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index ac4fdd30..475b7504 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -236,7 +236,9 @@ namespace Newtonsoft.Json.Linq ValidationUtils.ArgumentNotNull(key, "o"); if (!(key is int)) - throw new ArgumentException("Accessed JArray values with invalid key value: {0}. Array position index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key))); + { + throw new ArgumentException("Accessed JArray values with invalid key value: {0}. Int32 array index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key))); + } return GetItem((int)key); } @@ -245,7 +247,9 @@ namespace Newtonsoft.Json.Linq ValidationUtils.ArgumentNotNull(key, "o"); if (!(key is int)) - throw new ArgumentException("Set JArray values with invalid key value: {0}. Array position index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key))); + { + throw new ArgumentException("Set JArray values with invalid key value: {0}. Int32 array index expected.".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key))); + } SetItem((int)key, value); }