diff --git a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs index 3d6e406334..56474021db 100644 --- a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs +++ b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs @@ -758,6 +758,66 @@ public void Values_can_be_correctly_converted_to_nullable_ushort_without_the_par value.Should().Be(1234); } + + [Fact] + public void Values_can_be_correctly_converted_to_sbyte_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-us"); + + var value = option.Parse("-us 123").GetValueForOption(option); + + value.Should().Be(123); + } + + [Fact] + public void Values_can_be_correctly_converted_to_nullable_sbyte_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-x"); + + var value = option.Parse("-x 123").GetValueForOption(option); + + value.Should().Be(123); + } + + [Fact] + public void Values_can_be_correctly_converted_to_byte_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-us"); + + var value = option.Parse("-us 123").GetValueForOption(option); + + value.Should().Be(123); + } + + [Fact] + public void Values_can_be_correctly_converted_to_nullable_byte_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-x"); + + var value = option.Parse("-x 123").GetValueForOption(option); + + value.Should().Be(123); + } + + [Fact] + public void Values_can_be_correctly_converted_to_uint_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-us"); + + var value = option.Parse("-us 1234").GetValueForOption(option); + + value.Should().Be(1234); + } + + [Fact] + public void Values_can_be_correctly_converted_to_nullable_uint_without_the_parser_specifying_a_custom_converter() + { + var option = new Option("-x"); + + var value = option.Parse("-x 1234").GetValueForOption(option); + + value.Should().Be(1234); + } [Fact] public void Values_can_be_correctly_converted_to_array_of_int_without_the_parser_specifying_a_custom_converter() diff --git a/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs b/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs index 604b7b920c..3314be2c01 100644 --- a/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs +++ b/src/System.CommandLine/Binding/ArgumentConverter.StringConverters.cs @@ -163,6 +163,42 @@ internal static partial class ArgumentConverter return false; }, + [typeof(uint)] = (string token, out object? value) => + { + if (uint.TryParse(token, out var uintValue)) + { + value = uintValue; + return true; + } + + value = default; + return false; + }, + + [typeof(sbyte)] = (string token, out object? value) => + { + if (sbyte.TryParse(token, out var sbyteValue)) + { + value = sbyteValue; + return true; + } + + value = default; + return false; + }, + + [typeof(byte)] = (string token, out object? value) => + { + if (byte.TryParse(token, out var byteValue)) + { + value = byteValue; + return true; + } + + value = default; + return false; + }, + [typeof(string)] = (string input, out object? value) => { value = input; @@ -171,9 +207,9 @@ internal static partial class ArgumentConverter [typeof(ulong)] = (string token, out object? value) => { - if (ulong.TryParse(token, out var ushortValue)) + if (ulong.TryParse(token, out var ulongValue)) { - value = ushortValue; + value = ulongValue; return true; }