Skip to content

Commit 4712b0c

Browse files
committed
fix #1768
1 parent de20229 commit 4712b0c

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,18 @@ private static IList CreateEnumerable(Type type, Type itemType, int capacity = 0
4646

4747
if (type.IsGenericType)
4848
{
49-
var x = type.GetGenericTypeDefinition() switch
49+
var genericTypeDefinition = type.GetGenericTypeDefinition();
50+
51+
if (genericTypeDefinition == typeof(IEnumerable<>) ||
52+
genericTypeDefinition == typeof(IList<>) ||
53+
genericTypeDefinition == typeof(ICollection<>))
5054
{
51-
{ } enumerable when typeof(IEnumerable<>).IsAssignableFrom(enumerable) =>
52-
CreateArray(itemType, capacity),
53-
{ } array when typeof(IList<>).IsAssignableFrom(array) ||
54-
typeof(ICollection<>).IsAssignableFrom(array) =>
55-
CreateArray(itemType, capacity),
56-
{ } list when list == typeof(List<>) =>
57-
CreateEmptyList(type),
58-
_ => null
59-
};
55+
return CreateArray(itemType, capacity);
56+
}
6057

61-
if (x is { })
58+
if (genericTypeDefinition == typeof(List<>))
6259
{
63-
return x;
60+
return CreateEmptyList(type);
6461
}
6562
}
6663

0 commit comments

Comments
 (0)