File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
System.CommandLine.Tests/Binding
System.CommandLine/Binding Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,28 @@ public void Values_can_be_correctly_converted_to_nullable_float_without_the_pars
633
633
value . Should ( ) . Be ( 123.456f ) ;
634
634
}
635
635
636
+ [ Fact ]
637
+ public void Values_can_be_correctly_converted_to_Guid_without_the_parser_specifying_a_custom_converter ( )
638
+ {
639
+ var guidString = "75517282-018F-46BB-B15F-1D8DBFE23F6E" ;
640
+ var option = new Option < Guid > ( "-x" ) ;
641
+
642
+ var value = option . Parse ( $ "-x { guidString } ") . GetValueForOption ( option ) ;
643
+
644
+ value . Should ( ) . Be ( Guid . Parse ( guidString ) ) ;
645
+ }
646
+
647
+ [ Fact ]
648
+ public void Values_can_be_correctly_converted_to_nullable_Guid_without_the_parser_specifying_a_custom_converter ( )
649
+ {
650
+ var guidString = "75517282-018F-46BB-B15F-1D8DBFE23F6E" ;
651
+ var option = new Option < Guid ? > ( "-x" ) ;
652
+
653
+ var value = option . Parse ( $ "-x { guidString } ") . GetValueForOption ( option ) ;
654
+
655
+ value . Should ( ) . Be ( Guid . Parse ( guidString ) ) ;
656
+ }
657
+
636
658
[ Fact ]
637
659
public void Values_can_be_correctly_converted_to_Uri_without_the_parser_specifying_a_custom_converter ( )
638
660
{
Original file line number Diff line number Diff line change @@ -112,6 +112,18 @@ internal static partial class ArgumentConverter
112
112
value = default ;
113
113
return false ;
114
114
} ,
115
+
116
+ [ typeof ( Guid ) ] = ( string input , out object ? value ) =>
117
+ {
118
+ if ( Guid . TryParse ( input , out var parsed ) )
119
+ {
120
+ value = parsed ;
121
+ return true ;
122
+ }
123
+
124
+ value = default ;
125
+ return false ;
126
+ } ,
115
127
116
128
[ typeof ( int ) ] = ( string token , out object ? value ) =>
117
129
{
You can’t perform that action at this time.
0 commit comments