One way of implementing it (just an idea) is creating a new dedicated class (not a Value Tuple because it's a struct and JIT compiles a dedicated version of generic collections for every value type and we don't want that as it's a performance hit for startup scenarios).
The class should store string name and CommandResult parent as fields, implement IEqutable and override GetHashCode and be internal and sealed. Instances of this class could be keys of the mentioned dictionary and they should be added to the dictionary at the same time when ArgumentResult instances are being added to SymbolResultTree (the values of the dictionary should be instances of ArgumentResult).
|
_symbolResultTree.Add(argument, argumentResult); |
Finding all usages of SymbolResultTree.*Add* might be non-trivial, as the type derives from Dictionary. This can be changed, it's internal type and it was just a minor perf optimization.
When ParseResult.GetValue<T>(string name) is used, it should use the parsed CommandResult to find the value of given name in the context of parsed Command:
|
public CommandResult CommandResult { get; } |
Option<bool>(name: "help", aliases: new [] { "--help", "-h", "-?" })the lookup should match onlyhelp.Dictionary. No need to use a concurrent version of dictionary, as the creation will be single-threaded.One way of implementing it (just an idea) is creating a new dedicated class (not a Value Tuple because it's a
structand JIT compiles a dedicated version of generic collections for every value type and we don't want that as it's a performance hit for startup scenarios).The class should store
string nameandCommandResult parentas fields, implement IEqutable and overrideGetHashCodeand be internal and sealed. Instances of this class could be keys of the mentioned dictionary and they should be added to the dictionary at the same time whenArgumentResultinstances are being added toSymbolResultTree(the values of the dictionary should be instances ofArgumentResult).command-line-api/src/System.CommandLine/Parsing/ParseOperation.cs
Line 158 in 76437b0
Finding all usages of
SymbolResultTree.*Add*might be non-trivial, as the type derives fromDictionary. This can be changed, it's internal type and it was just a minor perf optimization.When
ParseResult.GetValue<T>(string name)is used, it should use the parsed CommandResult to find the value of given name in the context of parsed Command:command-line-api/src/System.CommandLine/ParseResult.cs
Line 65 in 76437b0