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
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public StringArgumentValue(string providedValue)
}
}

if (toType.IsArray && string.IsNullOrWhiteSpace(argumentValue))
{
return Array.CreateInstance(toType.GetElementType()!, 0);
}

return Convert.ChangeType(argumentValue, toType, resolutionContext.ReaderOptions.FormatProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,24 @@ public void StringValuesConvertToString(string expected)

Assert.Equal(expected, actual);
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void EmptyOrWhitespaceStringConvertsToEmptyArrayForArrayType(string input)
{
var value = new StringArgumentValue(input);
var actual = value.ConvertTo(typeof(string[]), new ResolutionContext());

var array = Assert.IsType<string[]>(actual);
Assert.Empty(array);
}

[Fact]
public void NonEmptyStringDoesNotConvertToArray()
{
var value = new StringArgumentValue("Information");
Assert.Throws<InvalidCastException>(() =>
value.ConvertTo(typeof(string[]), new ResolutionContext()));
}
}
Loading