This commit is contained in:
James Newton-King
2014-05-05 17:46:16 +12:00
parent 8078ab4511
commit a9884b7518
2 changed files with 13 additions and 13 deletions
@@ -67,7 +67,7 @@ namespace Newtonsoft.Json.Serialization
internal bool IsArray { get; private set; } internal bool IsArray { get; private set; }
internal bool ShouldCreateWrapper { get; private set; } internal bool ShouldCreateWrapper { get; private set; }
internal bool CanDeserialize { get; private set; } internal bool CanDeserialize { get; private set; }
internal MethodCall<object, object> ParametrizedConstructor { get; private set; } internal MethodCall<object, object> ParametrizedCreator { get; private set; }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="JsonArrayContract"/> class. /// Initializes a new instance of the <see cref="JsonArrayContract"/> class.
@@ -102,7 +102,7 @@ namespace Newtonsoft.Json.Serialization
CreatedType = typeof(List<object>); CreatedType = typeof(List<object>);
if (CollectionItemType != null) if (CollectionItemType != null)
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType); ParametrizedCreator = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection<>)); IsReadOnlyOrFixedSize = ReflectionUtils.InheritsGenericDefinition(underlyingType, typeof(ReadOnlyCollection<>));
canDeserialize = true; canDeserialize = true;
@@ -120,7 +120,7 @@ namespace Newtonsoft.Json.Serialization
CreatedType = typeof(HashSet<>).MakeGenericType(CollectionItemType); CreatedType = typeof(HashSet<>).MakeGenericType(CollectionItemType);
#endif #endif
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType); ParametrizedCreator = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
canDeserialize = true; canDeserialize = true;
ShouldCreateWrapper = true; ShouldCreateWrapper = true;
} }
@@ -134,9 +134,9 @@ namespace Newtonsoft.Json.Serialization
CreatedType = typeof(ReadOnlyCollection<>).MakeGenericType(CollectionItemType); CreatedType = typeof(ReadOnlyCollection<>).MakeGenericType(CollectionItemType);
_genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType); _genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType);
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, CollectionItemType); ParametrizedCreator = CollectionUtils.ResolveEnumableCollectionConstructor(CreatedType, CollectionItemType);
IsReadOnlyOrFixedSize = true; IsReadOnlyOrFixedSize = true;
canDeserialize = (ParametrizedConstructor != null); canDeserialize = (ParametrizedCreator != null);
} }
#endif #endif
else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable<>), out tempCollectionType)) else if (ReflectionUtils.ImplementsGenericDefinition(underlyingType, typeof(IEnumerable<>), out tempCollectionType))
@@ -146,13 +146,13 @@ namespace Newtonsoft.Json.Serialization
if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IEnumerable<>))) if (ReflectionUtils.IsGenericDefinition(UnderlyingType, typeof(IEnumerable<>)))
CreatedType = typeof(List<>).MakeGenericType(CollectionItemType); CreatedType = typeof(List<>).MakeGenericType(CollectionItemType);
ParametrizedConstructor = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType); ParametrizedCreator = CollectionUtils.ResolveEnumableCollectionConstructor(underlyingType, CollectionItemType);
#if !(NET35 || NET20 || NETFX_CORE) #if !(NET35 || NET20 || NETFX_CORE)
if (ParametrizedConstructor == null && underlyingType.Name == FSharpUtils.FSharpListTypeName) if (ParametrizedCreator == null && underlyingType.Name == FSharpUtils.FSharpListTypeName)
{ {
FSharpUtils.EnsureInitialized(underlyingType.Assembly()); FSharpUtils.EnsureInitialized(underlyingType.Assembly());
ParametrizedConstructor = FSharpUtils.CreateSeq(CollectionItemType); ParametrizedCreator = FSharpUtils.CreateSeq(CollectionItemType);
} }
#endif #endif
@@ -170,7 +170,7 @@ namespace Newtonsoft.Json.Serialization
IsReadOnlyOrFixedSize = true; IsReadOnlyOrFixedSize = true;
ShouldCreateWrapper = true; ShouldCreateWrapper = true;
canDeserialize = (ParametrizedConstructor != null); canDeserialize = (ParametrizedCreator != null);
} }
} }
else else
@@ -202,7 +202,7 @@ namespace Newtonsoft.Json.Serialization
if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, CollectionItemType, out immutableCreatedType, out immutableParameterizedCreator)) if (ImmutableCollectionsUtils.TryBuildImmutableForArrayContract(underlyingType, CollectionItemType, out immutableCreatedType, out immutableParameterizedCreator))
{ {
CreatedType = immutableCreatedType; CreatedType = immutableCreatedType;
ParametrizedConstructor = immutableParameterizedCreator; ParametrizedCreator = immutableParameterizedCreator;
IsReadOnlyOrFixedSize = true; IsReadOnlyOrFixedSize = true;
CanDeserialize = true; CanDeserialize = true;
} }
@@ -463,7 +463,7 @@ namespace Newtonsoft.Json.Serialization
if (contract.OnErrorCallbacks.Count > 0) if (contract.OnErrorCallbacks.Count > 0)
throw JsonSerializationException.Create(reader, "Cannot call OnError on readonly list, or dictionary created from a non-default constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType)); throw JsonSerializationException.Create(reader, "Cannot call OnError on readonly list, or dictionary created from a non-default constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
if (dictionaryContract.ParametrizedConstructor == null) if (dictionaryContract.ParametrizedCreator == null)
throw JsonSerializationException.Create(reader, "Cannot deserialize readonly or fixed size dictionary: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType)); throw JsonSerializationException.Create(reader, "Cannot deserialize readonly or fixed size dictionary: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
} }
@@ -471,7 +471,7 @@ namespace Newtonsoft.Json.Serialization
if (createdFromNonDefaultConstructor) if (createdFromNonDefaultConstructor)
{ {
return dictionaryContract.ParametrizedConstructor(null , new object[] { dictionary }); return dictionaryContract.ParametrizedCreator(null, new object[] { dictionary });
} }
else if (dictionary is IWrappedDictionary) else if (dictionary is IWrappedDictionary)
{ {
@@ -1057,7 +1057,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
createdFromNonDefaultConstructor = false; createdFromNonDefaultConstructor = false;
return (IDictionary)dictionary; return (IDictionary)dictionary;
} }
else if (contract.ParametrizedConstructor != null) else if (contract.ParametrizedCreator != null)
{ {
createdFromNonDefaultConstructor = true; createdFromNonDefaultConstructor = true;
return contract.CreateTemporaryDictionary(); return contract.CreateTemporaryDictionary();