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.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections ;
@@ -221,6 +221,21 @@ public void Nullable_bool_parses_as_null_when_the_option_has_not_been_applied()
221
221
. Be ( null ) ;
222
222
}
223
223
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
+
224
239
[ Fact ]
225
240
public void By_default_an_option_with_zero_or_one_argument_parses_as_the_argument_string_value ( )
226
241
{
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.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
4
using System . Collections ;
@@ -204,8 +204,8 @@ internal static ArgumentConversionResult ConvertIfNeeded(
204
204
toType ,
205
205
successful . Value ,
206
206
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 ? ) =>
209
209
Success ( conversionResult . Argument , true ) ,
210
210
211
211
NoArgumentConversionResult _ when conversionResult . Argument . Arity . MinimumNumberOfValues > 0 =>
You can’t perform that action at this time.
0 commit comments