File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed
System.CommandLine/Binding
System.CommandLine.Tests/Binding Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 8
8
using FluentAssertions ;
9
9
using System . Linq ;
10
10
using Xunit ;
11
+ using System . Net ;
11
12
12
13
namespace System . CommandLine . Tests . Binding
13
14
{
@@ -708,7 +709,29 @@ public void Values_can_be_correctly_converted_to_nullable_sbyte_without_the_pars
708
709
709
710
value . Should ( ) . Be ( 123 ) ;
710
711
}
711
-
712
+
713
+ [ Fact ]
714
+ public void Values_can_be_correctly_converted_to_ipaddress_without_the_parser_specifying_a_custom_converter ( )
715
+ {
716
+ var option = new Option < IPAddress > ( "-us" ) ;
717
+
718
+ var value = option . Parse ( "-us 1.2.3.4" ) . GetValueForOption ( option ) ;
719
+
720
+ value . Should ( ) . Be ( IPAddress . Parse ( "1.2.3.4" ) ) ;
721
+ }
722
+
723
+ #if NETCOREAPP3_0_OR_GREATER
724
+ [ Fact ]
725
+ public void Values_can_be_correctly_converted_to_ipendpoint_without_the_parser_specifying_a_custom_converter ( )
726
+ {
727
+ var option = new Option < IPEndPoint > ( "-us" ) ;
728
+
729
+ var value = option . Parse ( "-us 1.2.3.4:56" ) . GetValueForOption ( option ) ;
730
+
731
+ value . Should ( ) . Be ( IPEndPoint . Parse ( "1.2.3.4:56" ) ) ;
732
+ }
733
+ #endif
734
+
712
735
[ Fact ]
713
736
public void Values_can_be_correctly_converted_to_byte_without_the_parser_specifying_a_custom_converter ( )
714
737
{
Original file line number Diff line number Diff line change 3
3
4
4
using System . Collections . Generic ;
5
5
using System . IO ;
6
+ using System . Net ;
6
7
7
8
namespace System . CommandLine . Binding ;
8
9
@@ -154,6 +155,32 @@ internal static partial class ArgumentConverter
154
155
return false ;
155
156
} ,
156
157
158
+ [ typeof ( IPAddress ) ] = ( string token , out object ? value ) =>
159
+ {
160
+ if ( IPAddress . TryParse ( token , out var ip ) )
161
+ {
162
+ value = ip ;
163
+ return true ;
164
+ }
165
+
166
+ value = default ;
167
+ return false ;
168
+ } ,
169
+
170
+ #if NETCOREAPP3_0_OR_GREATER
171
+ [ typeof ( IPEndPoint ) ] = ( string token , out object ? value ) =>
172
+ {
173
+ if ( IPEndPoint . TryParse ( token , out var ipendpoint ) )
174
+ {
175
+ value = ipendpoint ;
176
+ return true ;
177
+ }
178
+
179
+ value = default ;
180
+ return false ;
181
+ } ,
182
+ #endif
183
+
157
184
[ typeof ( long ) ] = ( string token , out object ? value ) =>
158
185
{
159
186
if ( long . TryParse ( token , out var longValue ) )
You can’t perform that action at this time.
0 commit comments