-Improved JArray bad indexer message

This commit is contained in:
James Newton-King
2015-11-23 20:31:28 +13:00
parent 331fcc0ebb
commit a9c7d60d22
3 changed files with 8 additions and 4 deletions
@@ -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]
@@ -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]
+6 -2
View File
@@ -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);
}