Handle F# lists that implement IReadOnlyCollection<T> (F# 4.1 and above) (#1181)
Fixes #1180
This commit is contained in:
committed by
James Newton-King
parent
285b4c9a85
commit
7819b3c5ef
@@ -191,6 +191,11 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
_genericCollectionDefinitionType = typeof(List<>).MakeGenericType(CollectionItemType);
|
||||
_parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(CreatedType, CollectionItemType);
|
||||
|
||||
#if HAVE_FSHARP_TYPES
|
||||
StoreFSharpListCreatorIfNecessary(underlyingType);
|
||||
#endif
|
||||
|
||||
IsReadOnlyOrFixedSize = true;
|
||||
canDeserialize = HasParameterizedCreatorInternal;
|
||||
}
|
||||
@@ -207,11 +212,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
_parameterizedConstructor = CollectionUtils.ResolveEnumerableCollectionConstructor(underlyingType, CollectionItemType);
|
||||
|
||||
#if HAVE_FSHARP_TYPES
|
||||
if (!HasParameterizedCreatorInternal && underlyingType.Name == FSharpUtils.FSharpListTypeName)
|
||||
{
|
||||
FSharpUtils.EnsureInitialized(underlyingType.Assembly());
|
||||
_parameterizedCreator = FSharpUtils.CreateSeq(CollectionItemType);
|
||||
}
|
||||
StoreFSharpListCreatorIfNecessary(underlyingType);
|
||||
#endif
|
||||
|
||||
if (underlyingType.IsGenericType() && underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
|
||||
@@ -306,5 +307,16 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
return (IList)_genericTemporaryCollectionCreator();
|
||||
}
|
||||
|
||||
#if HAVE_FSHARP_TYPES
|
||||
private void StoreFSharpListCreatorIfNecessary(Type underlyingType)
|
||||
{
|
||||
if (!HasParameterizedCreatorInternal && underlyingType.Name == FSharpUtils.FSharpListTypeName)
|
||||
{
|
||||
FSharpUtils.EnsureInitialized(underlyingType.Assembly());
|
||||
_parameterizedCreator = FSharpUtils.CreateSeq(CollectionItemType);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user