Skip to content

Commit 74ae46e

Browse files
authored
remove ISymbol, IArgument, IIdentifierSymbol, IOption and ICommand interfaces (#1538)
* remove ISymbol, IArgument, IIdentifierSymbol, IOption and ICommand interfaces each of them had a single implementation and it was increasing the amount of types required to be JITted * remove redundant casts (perf)
1 parent 56b1505 commit 74ae46e

File tree

57 files changed

+233
-402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+233
-402
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 37 additions & 56 deletions
Large diffs are not rendered by default.

src/System.CommandLine.Benchmarks/CommandLine/Perf_Parser_NestedCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void SetupRootCommand()
5555
GenerateTestNestedCommands(rootCommand, TestCommandsDepth, TestCommandsDepth);
5656

5757
// Choose only one path from the commands tree for the test arguments string
58-
ISymbol currentCmd = rootCommand;
58+
Symbol currentCmd = rootCommand;
5959
while (currentCmd.Children.Count > 0)
6060
{
6161
currentCmd = currentCmd.Children[0];

src/System.CommandLine.Generator.CommandHandler/CommandExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class CommandExtensions
1818
public static void SetHandler<TDelegate>(
1919
this Command command,
2020
TDelegate @delegate,
21-
params ISymbol[] symbols)
21+
params Symbol[] symbols)
2222
{
2323
throw new InvalidOperationException(_messageForWhenGeneratorIsNotInUse);
2424
}

src/System.CommandLine.NamingConventionBinder/ModelBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private bool ShortCutTheBinding()
135135
bindingContext.ParseResult.CommandResult.LocalizationResources,
136136
out var boundValue)
137137
? (true, boundValue?.Value, true)
138-
: (false,(object?) null, false);
138+
: (false, null, false);
139139
}
140140

141141
private (bool success, object? newInstance, bool anyNonDefaults) InstanceFromSpecificConstructor(

src/System.CommandLine.NamingConventionBinder/SpecificSymbolValueSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public bool TryGetValue(IValueDescriptor valueDescriptor,
2121
var specificDescriptor = ValueDescriptor;
2222
switch (specificDescriptor)
2323
{
24-
case IOption option:
24+
case Option option:
2525
var optionResult = bindingContext?.ParseResult.FindResultFor(option);
2626
if (optionResult is not null)
2727
{
2828
boundValue = optionResult.GetValueOrDefault();
2929
return true;
3030
}
3131
break;
32-
case IArgument argument:
32+
case Argument argument:
3333
var argumentResult = bindingContext?.ParseResult.FindResultFor(argument);
3434
if (argumentResult is not null)
3535
{

src/System.CommandLine.Tests/CommandTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void Commands_can_have_aliases()
215215

216216
var result = command.Parse("that");
217217

218-
result.CommandResult.Command.Should().Be(command);
218+
result.CommandResult.Command.Should().BeSameAs(command);
219219
result.Errors.Should().BeEmpty();
220220
}
221221

@@ -229,7 +229,7 @@ public void RootCommand_can_have_aliases()
229229

230230
var result = command.Parse("that");
231231

232-
result.CommandResult.Command.Should().Be(command);
232+
result.CommandResult.Command.Should().BeSameAs(command);
233233
result.Errors.Should().BeEmpty();
234234
}
235235

@@ -246,7 +246,7 @@ public void Subcommands_can_have_aliases()
246246

247247
var result = rootCommand.Parse("that");
248248

249-
result.CommandResult.Command.Should().Be(subcommand);
249+
result.CommandResult.Command.Should().BeSameAs(subcommand);
250250
result.Errors.Should().BeEmpty();
251251
}
252252

src/System.CommandLine.Tests/Help/HelpBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class HelpBuilderExtensions
1010
{
1111
public static void Write(
1212
this HelpBuilder builder,
13-
ICommand command,
13+
Command command,
1414
TextWriter writer) =>
1515
builder.Write(new HelpContext(builder, command, writer));
1616
}

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ public void A_renamed_RootCommand_can_be_omitted_from_the_parsed_args()
838838
var result2 = rootCommand.Parse("outer inner -x hello");
839839
var result3 = rootCommand.Parse($"{RootCommand.ExecutableName} inner -x hello");
840840

841-
result2.RootCommandResult.Command.Should().Be(result1.RootCommandResult.Command);
842-
result3.RootCommandResult.Command.Should().Be(result1.RootCommandResult.Command);
841+
result2.RootCommandResult.Command.Should().BeSameAs(result1.RootCommandResult.Command);
842+
result3.RootCommandResult.Command.Should().BeSameAs(result1.RootCommandResult.Command);
843843
}
844844

845845
[Fact]
@@ -1069,19 +1069,19 @@ public void Option_and_Command_can_have_the_same_alias()
10691069
.CommandResult
10701070
.Command
10711071
.Should()
1072-
.Be(innerCommand);
1072+
.BeSameAs(innerCommand);
10731073

10741074
parser.Parse("outer --inner")
10751075
.CommandResult
10761076
.Command
10771077
.Should()
1078-
.Be(outerCommand);
1078+
.BeSameAs(outerCommand);
10791079

10801080
parser.Parse("outer --inner inner")
10811081
.CommandResult
10821082
.Command
10831083
.Should()
1084-
.Be(innerCommand);
1084+
.BeSameAs(innerCommand);
10851085

10861086
parser.Parse("outer --inner inner")
10871087
.CommandResult
@@ -1218,7 +1218,7 @@ public void Option_arguments_can_match_subcommands()
12181218
_output.WriteLine(result.ToString());
12191219

12201220
result.GetValueForOption(optionA).Should().Be("subcommand");
1221-
result.CommandResult.Command.Should().Be(root);
1221+
result.CommandResult.Command.Should().BeSameAs(root);
12221222
}
12231223

12241224
[Fact]
@@ -1236,7 +1236,7 @@ public void Arguments_can_match_subcommands()
12361236

12371237
var result = root.Parse("subcommand one two three subcommand four");
12381238

1239-
result.CommandResult.Command.Should().Be(subcommand);
1239+
result.CommandResult.Command.Should().BeSameAs(subcommand);
12401240

12411241
result.GetValueForArgument(argument)
12421242
.Should()
@@ -1681,7 +1681,7 @@ public void Empty_strings_in_parsed_args_array_are_ignored()
16811681

16821682
result.Errors.Should().BeEmpty();
16831683

1684-
result.CommandResult.Command.Should().Be(subcommand);
1684+
result.CommandResult.Command.Should().BeSameAs(subcommand);
16851685
result.FindResultFor(option).Should().NotBeNull();
16861686
}
16871687

src/System.CommandLine.Tests/ParsingValidationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ public void A_command_with_subcommands_is_valid_to_invoke_if_it_has_a_handler()
915915
var result = outer.Parse("outer inner");
916916

917917
result.Errors.Should().BeEmpty();
918-
result.CommandResult.Command.Should().Be(inner);
918+
result.CommandResult.Command.Should().BeSameAs(inner);
919919
}
920920

921921
[Fact]

src/System.CommandLine.Tests/SymbolSetExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.CommandLine.Tests
88
{
99
internal static class SymbolSetExtensions
1010
{
11-
internal static ISymbol GetByAlias(this SymbolSet symbolSet, string alias)
11+
internal static Symbol GetByAlias(this SymbolSet symbolSet, string alias)
1212
=> symbolSet.SingleOrDefault(symbol => symbol.Name.Equals(alias) || symbol is IdentifierSymbol id && id.HasAlias(alias));
1313

1414
internal static bool ContainsAlias(this SymbolSet symbolSet, string alias)

0 commit comments

Comments
 (0)