Skip to content

Commit c2a4654

Browse files
committed
fix #1647
1 parent 6b5bba3 commit c2a4654

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/System.CommandLine.Tests/Binding/TypeConversionTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation and contributors. All rights reserved.
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections;
@@ -221,6 +221,21 @@ public void Nullable_bool_parses_as_null_when_the_option_has_not_been_applied()
221221
.Be(null);
222222
}
223223

224+
[Fact] // https://github.com/dotnet/command-line-api/issues/1647
225+
public void Generic_option_bool_parses_when_passed_to_non_generic_GetValueForOption()
226+
{
227+
var option = new Option<bool>("-b");
228+
229+
var cmd = new RootCommand
230+
{
231+
option
232+
};
233+
234+
var parseResult = cmd.Parse("-b");
235+
236+
parseResult.GetValueForOption((Option)option).Should().Be(true);
237+
}
238+
224239
[Fact]
225240
public void By_default_an_option_with_zero_or_one_argument_parses_as_the_argument_string_value()
226241
{

src/System.CommandLine/Binding/ArgumentConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation and contributors. All rights reserved.
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections;
@@ -204,8 +204,8 @@ internal static ArgumentConversionResult ConvertIfNeeded(
204204
toType,
205205
successful.Value,
206206
symbolResult.LocalizationResources),
207-
208-
NoArgumentConversionResult _ when toType == typeof(bool) || toType == typeof(bool?) =>
207+
208+
NoArgumentConversionResult _ when conversionResult.Argument.ValueType == typeof(bool) || conversionResult.Argument.ValueType == typeof(bool?) =>
209209
Success(conversionResult.Argument, true),
210210

211211
NoArgumentConversionResult _ when conversionResult.Argument.Arity.MinimumNumberOfValues > 0 =>

0 commit comments

Comments
 (0)