File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
System.CommandLine.Tests/Binding
System.CommandLine/Binding Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 55using System . CommandLine . Binding ;
66using System . CommandLine . Builder ;
77using System . CommandLine . Invocation ;
8+ using System . CommandLine . IO ;
89using System . CommandLine . Parsing ;
910using System . IO ;
1011using FluentAssertions ;
@@ -769,5 +770,29 @@ public async Task Empty_input_is_bound_correctly_to_list_type_properties()
769770
770771 boundInstance . Should ( ) . NotBeNull ( ) ;
771772 }
773+
774+ [ Fact ]
775+ public async Task Decimals_are_bound_correctly_when_no_token_is_matched ( )
776+ {
777+ decimal ? receivedValue = null ;
778+
779+ var rootCommand = new RootCommand
780+ {
781+ new Option < decimal > ( "--opt-decimal" )
782+ } ;
783+ rootCommand . Handler = CommandHandler . Create ( ( ComplexType options ) =>
784+ {
785+ receivedValue = options . OptDecimal ;
786+ } ) ;
787+
788+ await rootCommand . InvokeAsync ( "" ) ;
789+
790+ receivedValue . Should ( ) . Be ( 0 ) ;
791+ }
792+
793+ public class ComplexType
794+ {
795+ public decimal OptDecimal { get ; set ; }
796+ }
772797 }
773798}
Original file line number Diff line number Diff line change @@ -105,7 +105,8 @@ private bool ShortCutTheBinding()
105105 var modelType = ModelDescriptor . ModelType ;
106106 return modelType . IsPrimitive ||
107107 modelType . IsNullableValueType ( ) ||
108- modelType == typeof ( string ) ;
108+ modelType == typeof ( string ) ||
109+ modelType == typeof ( decimal ) ;
109110 }
110111
111112 private ( bool success , object ? newInstance , bool anyNonDefaults ) GetSimpleModelValue (
You can’t perform that action at this time.
0 commit comments