diff --git a/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs b/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs index 67eb351539..b569a2ffef 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs @@ -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); } }