From d2364a7a2ce758ff7c0e9c7fa1a6784bd7c3a635 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 7 Mar 2023 20:29:10 +0100 Subject: [PATCH] remove non-generic GetValueOrDefault and fix the usages --- ...Tests.System_CommandLine_api_is_not_changed.approved.txt | 2 -- .../CommandResultExtensions.cs | 4 ++-- .../SpecificSymbolValueSource.cs | 4 ++-- src/System.CommandLine.Tests/ArgumentTests.cs | 4 ++-- src/System.CommandLine.Tests/Binding/TypeConversionTests.cs | 2 +- src/System.CommandLine.Tests/OptionTests.cs | 6 +++--- .../ParserTests.MultipleArguments.cs | 4 ++-- src/System.CommandLine/Parsing/ArgumentResult.cs | 4 ---- src/System.CommandLine/Parsing/OptionResult.cs | 6 ------ 9 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index 9688ad3dcf..953d04d63b 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -332,7 +332,6 @@ System.CommandLine.Parsing public class ArgumentResult : SymbolResult public System.CommandLine.Argument Argument { get; } public System.Void AddError(System.String errorMessage) - public System.Object GetValueOrDefault() public T GetValueOrDefault() public System.Void OnlyTake(System.Int32 numberOfTokens) public System.String ToString() @@ -351,7 +350,6 @@ System.CommandLine.Parsing public System.Boolean IsImplicit { get; } public System.CommandLine.Option Option { get; } public Token Token { get; } - public System.Object GetValueOrDefault() public T GetValueOrDefault() public System.String ToString() public class ParseError diff --git a/src/System.CommandLine.NamingConventionBinder/CommandResultExtensions.cs b/src/System.CommandLine.NamingConventionBinder/CommandResultExtensions.cs index 1da0d4e9b6..dfc279e892 100644 --- a/src/System.CommandLine.NamingConventionBinder/CommandResultExtensions.cs +++ b/src/System.CommandLine.NamingConventionBinder/CommandResultExtensions.cs @@ -22,7 +22,7 @@ internal static bool TryGetValueForArgument( { if (commandResult.FindResultFor(argument) is { } argumentResult) { - value = argumentResult.GetValueOrDefault(); + value = argumentResult.GetValueOrDefault(); } else { @@ -57,7 +57,7 @@ internal static bool TryGetValueForOption( if (optionResult is not null) { - value = optionResult.GetValueOrDefault(); + value = optionResult.GetValueOrDefault(); return true; } diff --git a/src/System.CommandLine.NamingConventionBinder/SpecificSymbolValueSource.cs b/src/System.CommandLine.NamingConventionBinder/SpecificSymbolValueSource.cs index e9ebab7a6c..38a321eab6 100644 --- a/src/System.CommandLine.NamingConventionBinder/SpecificSymbolValueSource.cs +++ b/src/System.CommandLine.NamingConventionBinder/SpecificSymbolValueSource.cs @@ -25,7 +25,7 @@ public bool TryGetValue(IValueDescriptor valueDescriptor, var optionResult = bindingContext?.ParseResult.FindResultFor(option); if (optionResult is not null) { - boundValue = optionResult.GetValueOrDefault(); + boundValue = optionResult.GetValueOrDefault(); return true; } break; @@ -33,7 +33,7 @@ public bool TryGetValue(IValueDescriptor valueDescriptor, var argumentResult = bindingContext?.ParseResult.FindResultFor(argument); if (argumentResult is not null) { - boundValue = argumentResult.GetValueOrDefault(); + boundValue = argumentResult.GetValueOrDefault(); return true; } break; diff --git a/src/System.CommandLine.Tests/ArgumentTests.cs b/src/System.CommandLine.Tests/ArgumentTests.cs index 6bc7d9d649..92f2af8939 100644 --- a/src/System.CommandLine.Tests/ArgumentTests.cs +++ b/src/System.CommandLine.Tests/ArgumentTests.cs @@ -608,13 +608,13 @@ public void Custom_parser_can_pass_on_remaining_tokens(string commandLine) var parseResult = command.Parse(commandLine); parseResult.FindResultFor(argument1) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .BeEquivalentTo(new[] { 1, 2, 3 }, options => options.WithStrictOrdering()); parseResult.FindResultFor(argument2) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .BeEquivalentTo(new[] { 4, 5, 6, 7, 8 }, options => options.WithStrictOrdering()); diff --git a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs index 8435b13bd8..31b47b9301 100644 --- a/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs +++ b/src/System.CommandLine.Tests/Binding/TypeConversionTests.cs @@ -847,7 +847,7 @@ public void Max_arity_greater_than_1_converts_to_enumerable_types( var result = command.Parse("--items one --items two --items three"); result.Errors.Should().BeEmpty(); - result.FindResultFor(option).GetValueOrDefault().Should().BeAssignableTo(argumentType); + result.FindResultFor(option).GetValueOrDefault().Should().BeAssignableTo(argumentType); } [Fact] diff --git a/src/System.CommandLine.Tests/OptionTests.cs b/src/System.CommandLine.Tests/OptionTests.cs index c6e4508eba..4b93fb176d 100644 --- a/src/System.CommandLine.Tests/OptionTests.cs +++ b/src/System.CommandLine.Tests/OptionTests.cs @@ -237,7 +237,7 @@ public void Option_T_default_value_can_be_set_via_the_constructor() new RootCommand { option } .Parse("") .FindResultFor(option) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .Be(123); } @@ -253,7 +253,7 @@ public void Option_T_default_value_can_be_set_after_instantiation() new RootCommand { option } .Parse("") .FindResultFor(option) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .Be(123); } @@ -268,7 +268,7 @@ public void Option_T_default_value_factory_can_be_set_after_instantiation() new RootCommand { option } .Parse("") .FindResultFor(option) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .Be(123); } diff --git a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs index 2f157b5731..01e79f3056 100644 --- a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs +++ b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs @@ -127,12 +127,12 @@ public void Multiple_arguments_of_unspecified_type_are_parsed_correctly() var result = root.Parse("src.txt dest.txt"); result.FindResultFor(sourceArg) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .Be("src.txt"); result.FindResultFor(destinationArg) - .GetValueOrDefault() + .GetValueOrDefault() .Should() .Be("dest.txt"); } diff --git a/src/System.CommandLine/Parsing/ArgumentResult.cs b/src/System.CommandLine/Parsing/ArgumentResult.cs index fb775a0368..022ee2547e 100644 --- a/src/System.CommandLine/Parsing/ArgumentResult.cs +++ b/src/System.CommandLine/Parsing/ArgumentResult.cs @@ -34,10 +34,6 @@ internal ArgumentResult( internal ArgumentConversionResult GetArgumentConversionResult() => _conversionResult ??= ValidateAndConvert(useValidators: true); - /// - public object? GetValueOrDefault() => - GetValueOrDefault(); - /// /// Gets the parsed value or the default value for . /// diff --git a/src/System.CommandLine/Parsing/OptionResult.cs b/src/System.CommandLine/Parsing/OptionResult.cs index 84d5db181e..07c41a85ea 100644 --- a/src/System.CommandLine/Parsing/OptionResult.cs +++ b/src/System.CommandLine/Parsing/OptionResult.cs @@ -44,12 +44,6 @@ internal OptionResult( /// public override string ToString() => $"{nameof(OptionResult)}: {Token?.Value ?? Option.Name} {string.Join(" ", Tokens.Select(t => t.Value))}"; - /// - public object? GetValueOrDefault() => - Option.ValueType == typeof(bool) - ? GetValueOrDefault() - : GetValueOrDefault(); - /// /// Gets the parsed value or the default value for . ///