Skip to content

Commit dfee19f

Browse files
author
Bart Koelman
committed
Add support for IReadOnlySet<> usage in resource models
1 parent 5d164f0 commit dfee19f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/JsonApiDotNetCore/CollectionConverter.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ namespace JsonApiDotNetCore
88
{
99
internal sealed class CollectionConverter
1010
{
11-
private static readonly Type[] HashSetCompatibleCollectionTypes =
11+
private static readonly ISet<Type> HashSetCompatibleCollectionTypes = new HashSet<Type>
1212
{
1313
typeof(HashSet<>),
14-
typeof(ICollection<>),
1514
typeof(ISet<>),
16-
typeof(IEnumerable<>),
17-
typeof(IReadOnlyCollection<>)
15+
typeof(IReadOnlySet<>),
16+
typeof(ICollection<>),
17+
typeof(IReadOnlyCollection<>),
18+
typeof(IEnumerable<>)
1819
};
1920

2021
/// <summary>
@@ -49,15 +50,14 @@ public Type ToConcreteCollectionType(Type collectionType)
4950
{
5051
if (collectionType.IsInterface && collectionType.IsGenericType)
5152
{
52-
Type genericTypeDefinition = collectionType.GetGenericTypeDefinition();
53+
Type openCollectionType = collectionType.GetGenericTypeDefinition();
5354

54-
if (genericTypeDefinition == typeof(ICollection<>) || genericTypeDefinition == typeof(ISet<>) ||
55-
genericTypeDefinition == typeof(IEnumerable<>) || genericTypeDefinition == typeof(IReadOnlyCollection<>))
55+
if (HashSetCompatibleCollectionTypes.Contains(openCollectionType))
5656
{
5757
return typeof(HashSet<>).MakeGenericType(collectionType.GenericTypeArguments[0]);
5858
}
5959

60-
if (genericTypeDefinition == typeof(IList<>) || genericTypeDefinition == typeof(IReadOnlyList<>))
60+
if (openCollectionType == typeof(IList<>) || openCollectionType == typeof(IReadOnlyList<>))
6161
{
6262
return typeof(List<>).MakeGenericType(collectionType.GenericTypeArguments[0]);
6363
}

0 commit comments

Comments
 (0)