Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,18 @@ private static IList CreateEnumerable(Type type, Type itemType, int capacity = 0

if (type.IsGenericType)
{
var x = type.GetGenericTypeDefinition() switch
var genericTypeDefinition = type.GetGenericTypeDefinition();

if (genericTypeDefinition == typeof(IEnumerable<>) ||
genericTypeDefinition == typeof(IList<>) ||
genericTypeDefinition == typeof(ICollection<>))
{
{ } enumerable when typeof(IEnumerable<>).IsAssignableFrom(enumerable) =>
CreateArray(itemType, capacity),
{ } array when typeof(IList<>).IsAssignableFrom(array) ||
typeof(ICollection<>).IsAssignableFrom(array) =>
CreateArray(itemType, capacity),
{ } list when list == typeof(List<>) =>
CreateEmptyList(type),
_ => null
};
return CreateArray(itemType, capacity);
}

if (x is { })
if (genericTypeDefinition == typeof(List<>))
{
return x;
return CreateEmptyList(type);
}
}

Expand Down