diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 2140db10..44ab36e9 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -56,17 +56,17 @@ namespace Newtonsoft.Json.Tests Assert.AreEqual(JsonToken.StartArray, reader.TokenType); Assert.IsTrue(reader.Read()); - Assert.AreEqual(1.0d, reader.Value); + Assert.AreEqual(1.0m, reader.Value); Assert.AreEqual(typeof(decimal), reader.ValueType); Assert.AreEqual(JsonToken.Float, reader.TokenType); Assert.IsTrue(reader.Read()); - Assert.AreEqual(1, reader.Value); + Assert.AreEqual(1l, reader.Value); Assert.AreEqual(typeof(long), reader.ValueType); Assert.AreEqual(JsonToken.Integer, reader.TokenType); Assert.IsTrue(reader.Read()); - Assert.AreEqual(9.9d, reader.Value); + Assert.AreEqual(9.9m, reader.Value); Assert.AreEqual(typeof(decimal), reader.ValueType); Assert.AreEqual(JsonToken.Float, reader.TokenType); diff --git a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs index ff2a72c5..7b43ad6b 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JValueTests.cs @@ -59,7 +59,7 @@ namespace Newtonsoft.Json.Tests.Linq FloatParseHandling = Json.FloatParseHandling.Decimal }); - Assert.AreEqual(9.9d, v.Value); + Assert.AreEqual(9.9m, v.Value); Assert.AreEqual(typeof(decimal), v.Value.GetType()); } diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index f6c76867..f3ed21b2 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.1.15926")] +[assembly: AssemblyFileVersion("5.0.1.15929")] diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 3876d65c..43224f74 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -3922,7 +3922,7 @@ To fix this error either change the environment to be fully trusted, change the }); Assert.AreEqual(typeof(decimal), dic["value"].GetType()); - Assert.AreEqual(9.9d, dic["value"]); + Assert.AreEqual(9.9m, dic["value"]); } [Test] diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 01411f3c..59c058ab 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -90,6 +90,6 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.1.15926")] +[assembly: AssemblyFileVersion("5.0.1.15929")] [assembly: CLSCompliant(true)] diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index 9fd118e2..87af9890 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -129,35 +129,44 @@ namespace Newtonsoft.Json.Serialization canDeserialize = true; ShouldCreateWrapper = true; } - else if (underlyingType.IsGenericType() && underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) +#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) + else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof (IReadOnlyCollection<>), out tempCollectionType)) { - _genericCollectionDefinitionType = typeof(IEnumerable<>); CollectionItemType = underlyingType.GetGenericArguments()[0]; - IsReadOnlyOrFixedSize = true; - canDeserialize = true; + TemporaryCollectionType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + ShouldCreateWrapper = !typeof(IList).IsAssignableFrom(underlyingType); + + canDeserialize = (ResolveReadOnlyCollectionConstructor(underlyingType, CollectionItemType) != null + || underlyingType.GetGenericTypeDefinition() == typeof(IReadOnlyCollection<>) + || underlyingType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>)); } - else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable<>), out tempCollectionType)) +#endif + else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof (IEnumerable<>), out tempCollectionType)) { CollectionItemType = tempCollectionType.GetGenericArguments()[0]; - IsReadOnlyOrFixedSize = true; - canDeserialize = (ResolveReadOnlyCollectionConstructor(underlyingType, CollectionItemType) != null); - TemporaryCollectionType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); - } -#if !(NET40 || NET35 || NET20 || SILVERLIGHT || WINDOWS_PHONE || PORTABLE) - else if (underlyingType.IsGenericType() && underlyingType.GetGenericTypeDefinition() == typeof(IReadOnlyCollection<>)) - { - CollectionItemType = underlyingType.GetGenericArguments()[0]; - IsReadOnlyOrFixedSizeCollection = true; + if (underlyingType.GetGenericTypeDefinition() == typeof (IEnumerable<>)) + { + _genericCollectionDefinitionType = tempCollectionType; - _readOnlyCollectionConstructor = ResolveReadOnlyCollectionConstructor(underlyingType, CollectionItemType); + IsReadOnlyOrFixedSize = false; + ShouldCreateWrapper = false; + canDeserialize = true; + } + else + { + IsReadOnlyOrFixedSize = true; + ShouldCreateWrapper = true; + canDeserialize = (ResolveReadOnlyCollectionConstructor(underlyingType, CollectionItemType) != null); + TemporaryCollectionType = ReflectionUtils.MakeGenericType(typeof(List<>), CollectionItemType); + } } -#endif else { // types that implement IEnumerable and nothing else canDeserialize = false; + ShouldCreateWrapper = true; } CanDeserialize = canDeserialize; @@ -183,7 +192,7 @@ namespace Newtonsoft.Json.Serialization { Type tempCollectionItemType = tempCollectionType.GetGenericArguments()[0]; if (ReflectionUtils.IsNullableType(tempCollectionItemType)) - _createWrapper = true; + ShouldCreateWrapper = true; } #endif diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index bb674b2b..c246f3b9 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Serialization case JsonContractType.Array: JsonArrayContract arrayContract = (JsonArrayContract) valueContract; if (!arrayContract.IsMultidimensionalArray) - SerializeList(writer, (value.ShouldCreateWrapper) ? arrayContract.CreateWrapper(value) : (IList) value, arrayContract, member, containerContract, containerProperty); + SerializeList(writer, (value is IList) ? (IList)value : arrayContract.CreateWrapper(value), arrayContract, member, containerContract, containerProperty); else SerializeMultidimensionalArray(writer, (Array)value, arrayContract, member, containerContract, containerProperty); break;