From 3bb09e9507337d0726fd430425346b39206bc01f Mon Sep 17 00:00:00 2001 From: Kevin Kahl Date: Fri, 12 Aug 2022 22:03:24 -0700 Subject: [PATCH] Make Token.Symbol property public Motivation: - Inside custom middleware, it may be desirable to understand relative order of symbols in the parsed command line (for e.g. in the case of several option types that influence a shared setting and that have a "last option specified wins" semantic). - Best way to do understand sequence order is by inspecting the `ParseResult.Tokens` list. This gives `Token`s, which contain embedded symbol references. - From there, we'd like to compare the token's `Symbol` directly against predefined `Argument` and `Option` objects to ease identification. - Doing this from non-`internal` code today requires something like `if (tokenOfInterest == new Token(tokenOfInterest.Value, TokenType.Option, optionOfInterest)) { /* match */ ... }`, which works because of the overridden `Token.Equals` method. - It'd be much easier to say `if (tokenOfInterest.Symbol == optionOfInterest) { /* match */ ... }` - No clear reason why `Token.Symbol` needs to be `internal` --- src/System.CommandLine/Parsing/Token.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.CommandLine/Parsing/Token.cs b/src/System.CommandLine/Parsing/Token.cs index 7b656c9886..af015181f1 100644 --- a/src/System.CommandLine/Parsing/Token.cs +++ b/src/System.CommandLine/Parsing/Token.cs @@ -46,7 +46,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// /// The Symbol represented by the token (if any). /// - internal Symbol? Symbol { get; } + public Symbol? Symbol { get; } /// public override bool Equals(object? obj) => obj is Token other && Equals(other);