Description
- Providing name should be mandatory when creating Argument<T> and Option<T> #2051 needs to be implemented first. The method should work only for the names (no short aliases). So if user defines
Option<bool>(name: "help", aliases: new [] { "--help", "-h", "-?" })
the lookup should match onlyhelp
. - The users might define a parse tree where there are multiple arguments/options with the same name. But conflicts are not allowed on the Command level. The method should handle that properly.
- The method needs to handle default values properly (value not specified in args, default value factory used to create it).
- The lookup needs to be fast, so it should be backed by a
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 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
).
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: