File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
System.CommandLine.Tests/Binding
System.CommandLine/Binding Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 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
44using 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 {
Original file line number Diff line number Diff line change 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
44using 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 =>
You can’t perform that action at this time.
0 commit comments