-Fixed deserializing non-generic IReadOnlyCollection<T> implementations

This commit is contained in:
James Newton-King
2014-05-12 13:40:48 +12:00
parent 7a8f5e43bc
commit 017a38c65b
5 changed files with 56 additions and 4 deletions
@@ -1488,8 +1488,58 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(2, products.Count);
Assert.AreEqual("Product 1", products[0].Name);
}
#if !(NET40 || NET35 || NET20 || PORTABLE40)
[Test]
public void ReadOnlyIntegerList()
{
ReadOnlyIntegerList l = new ReadOnlyIntegerList(new List<int>
{
1,
2,
3,
int.MaxValue
});
string json = JsonConvert.SerializeObject(l, Formatting.Indented);
Assert.AreEqual(@"[
1,
2,
3,
2147483647
]", json);
}
#endif
}
#if !(NET40 || NET35 || NET20 || PORTABLE40)
public class ReadOnlyIntegerList : IReadOnlyCollection<int>
{
private readonly List<int> _list;
public ReadOnlyIntegerList(List<int> l)
{
_list = l;
}
public int Count
{
get { return _list.Count; }
}
public IEnumerator<int> GetEnumerator()
{
return _list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
#endif
public class Array2D
{
public string Before { get; set; }