diff --git a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs index a41bb1e9..d7f4106f 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs @@ -115,7 +115,6 @@ namespace Newtonsoft.Json.Serialization public JsonArrayContract(Type underlyingType) : base(underlyingType) { - var t = ReflectionUtils.EnsureNotByRefType(ReflectionUtils.EnsureNotNullableType(underlyingType)); ContractType = JsonContractType.Array; IsArray = CreatedType.IsArray; @@ -131,58 +130,58 @@ namespace Newtonsoft.Json.Serialization canDeserialize = true; IsMultidimensionalArray = (IsArray && UnderlyingType.GetArrayRank() > 1); } - else if (typeof(IList).IsAssignableFrom(t)) + else if (typeof(IList).IsAssignableFrom(NonNullableUnderlyingType)) { - if (ReflectionUtils.ImplementsGenericDefinition(t, typeof(ICollection<>), out _genericCollectionDefinitionType)) + if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(ICollection<>), out _genericCollectionDefinitionType)) { CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0]; } else { - CollectionItemType = ReflectionUtils.GetCollectionItemType(t); + CollectionItemType = ReflectionUtils.GetCollectionItemType(NonNullableUnderlyingType); } - if (t == typeof(IList)) + if (NonNullableUnderlyingType == typeof(IList)) { CreatedType = typeof(List); } if (CollectionItemType != null) { - _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(t, CollectionItemType); + _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(NonNullableUnderlyingType, CollectionItemType); } - IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(t, typeof(ReadOnlyCollection<>)); + IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(NonNullableUnderlyingType, typeof(ReadOnlyCollection<>)); canDeserialize = true; } - else if (ReflectionUtils.ImplementsGenericDefinition(t, typeof(ICollection<>), out _genericCollectionDefinitionType)) + else if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(ICollection<>), out _genericCollectionDefinitionType)) { CollectionItemType = _genericCollectionDefinitionType.GetGenericArguments()[0]; - if (ReflectionUtils.IsGenericDefinition(t, typeof(ICollection<>)) - || ReflectionUtils.IsGenericDefinition(t, typeof(IList<>))) + if (ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(ICollection<>)) + || ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(IList<>))) { CreatedType = typeof(List<>).MakeGenericType(CollectionItemType); } #if HAVE_ISET - if (ReflectionUtils.IsGenericDefinition(t, typeof(ISet<>))) + if (ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(ISet<>))) { CreatedType = typeof(HashSet<>).MakeGenericType(CollectionItemType); } #endif - _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(t, CollectionItemType); + _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(NonNullableUnderlyingType, CollectionItemType); canDeserialize = true; ShouldCreateWrapper = true; } #if HAVE_READ_ONLY_COLLECTIONS - else if (ReflectionUtils.ImplementsGenericDefinition(t, typeof(IReadOnlyCollection<>), out tempCollectionType)) + else if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(IReadOnlyCollection<>), out tempCollectionType)) { CollectionItemType = tempCollectionType.GetGenericArguments()[0]; - if (ReflectionUtils.IsGenericDefinition(t, typeof(IReadOnlyCollection<>)) - || ReflectionUtils.IsGenericDefinition(t, typeof(IReadOnlyList<>))) + if (ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(IReadOnlyCollection<>)) + || ReflectionUtils.IsGenericDefinition(NonNullableUnderlyingType, typeof(IReadOnlyList<>))) { CreatedType = typeof(ReadOnlyCollection<>).MakeGenericType(CollectionItemType); } @@ -191,14 +190,14 @@ namespace Newtonsoft.Json.Serialization _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(CreatedType, CollectionItemType); #if HAVE_FSHARP_TYPES - StoreFSharpListCreatorIfNecessary(t); + StoreFSharpListCreatorIfNecessary(NonNullableUnderlyingType); #endif IsReadOnlyOrFixedSize = true; canDeserialize = HasParameterizedCreatorInternal; } #endif - else if (ReflectionUtils.ImplementsGenericDefinition(t, typeof(IEnumerable<>), out tempCollectionType)) + else if (ReflectionUtils.ImplementsGenericDefinition(NonNullableUnderlyingType, typeof(IEnumerable<>), out tempCollectionType)) { CollectionItemType = tempCollectionType.GetGenericArguments()[0]; @@ -207,13 +206,13 @@ namespace Newtonsoft.Json.Serialization CreatedType = typeof(List<>).MakeGenericType(CollectionItemType); } - _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(t, CollectionItemType); + _parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(NonNullableUnderlyingType, CollectionItemType); #if HAVE_FSHARP_TYPES - StoreFSharpListCreatorIfNecessary(t); + StoreFSharpListCreatorIfNecessary(NonNullableUnderlyingType); #endif - if (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + if (NonNullableUnderlyingType.IsGenericType() && NonNullableUnderlyingType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) { _genericCollectionDefinitionType = tempCollectionType; @@ -253,7 +252,7 @@ namespace Newtonsoft.Json.Serialization #endif if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract( - t, + NonNullableUnderlyingType, CollectionItemType, out Type immutableCreatedType, out ObjectConstructor immutableParameterizedCreator))