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 5
5
using System . CommandLine . Binding ;
6
6
using System . CommandLine . Builder ;
7
7
using System . CommandLine . Invocation ;
8
+ using System . CommandLine . IO ;
8
9
using System . CommandLine . Parsing ;
9
10
using System . IO ;
10
11
using FluentAssertions ;
@@ -769,5 +770,29 @@ public async Task Empty_input_is_bound_correctly_to_list_type_properties()
769
770
770
771
boundInstance . Should ( ) . NotBeNull ( ) ;
771
772
}
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
+ }
772
797
}
773
798
}
Original file line number Diff line number Diff line change @@ -105,7 +105,8 @@ private bool ShortCutTheBinding()
105
105
var modelType = ModelDescriptor . ModelType ;
106
106
return modelType . IsPrimitive ||
107
107
modelType . IsNullableValueType ( ) ||
108
- modelType == typeof ( string ) ;
108
+ modelType == typeof ( string ) ||
109
+ modelType == typeof ( decimal ) ;
109
110
}
110
111
111
112
private ( bool success , object ? newInstance , bool anyNonDefaults ) GetSimpleModelValue (
You can’t perform that action at this time.
0 commit comments