Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/CommandLineUtils/Abstractions/ValueParserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public IValueParser GetParser(Type type)
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}

// For array and collection types, return a parser for the element type
if (type.IsArray)
{
var elementType = type.GetElementType();
if (elementType != null)
{
return GetParser(elementType);
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private string[] ExtractNamesFromEnum(Type? type)

if (ReflectionHelper.IsEnumerableType(type, out var wrappedEnumerableType))
{
return ExtractNamesFromEnum(wrappedType2);
return ExtractNamesFromEnum(wrappedEnumerableType);
}

if (type.IsEnum)
Expand Down
17 changes: 13 additions & 4 deletions src/CommandLineUtils/Internal/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,20 @@ public static bool IsSpecialTupleType(Type type, [NotNullWhen(true)] out Type? w

public static bool IsEnumerableType(Type type, [NotNullWhen(true)] out Type? wrappedType)
{
var result = type.IsGenericType &&
type.IsAssignableTo(typeof(IEnumerable<>));
wrappedType = result ? type.GenericTypeArguments[1] : null;
if (type.IsArray)
{
wrappedType = type.GetElementType()!;
return true;
}

return result;
if (type.IsGenericType)
{
wrappedType = type.GenericTypeArguments[0];
return true;
}

wrappedType = null;
return false;
}

private static IEnumerable<MemberInfo> GetAllMembers(Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ SomeNullableEnumArgument nullable enum arg desc.
Allowed values are: None, Normal, Extreme.
--enumOpt4[:<E>] nullable enum option desc.
Allowed values are: None, Normal, Extreme.
--enumOpt5[:<E>] multiple enum option desc.
--enumOpt5 <E> multiple enum option desc.
Allowed values are: None, Normal, Extreme.

",
Expand Down
Loading