[PROPOSED] Unify CustomParser and DefaultValueFactory#2791
Draft
jonsequitur wants to merge 1 commit intodotnet:mainfrom
Draft
[PROPOSED] Unify CustomParser and DefaultValueFactory#2791jonsequitur wants to merge 1 commit intodotnet:mainfrom
CustomParser and DefaultValueFactory#2791jonsequitur wants to merge 1 commit intodotnet:mainfrom
Conversation
9197564 to
b3f7a8c
Compare
b3f7a8c to
f29df73
Compare
jonsequitur
commented
Apr 2, 2026
| /// Specifies when a value factory should be invoked. | ||
| /// </summary> | ||
| [Flags] | ||
| public enum ValueFactoryInvocation |
Contributor
Author
There was a problem hiding this comment.
This clearly needs a better name. It indicates when the value factory should be called, based on whether or not a symbol has matching tokens.
|
I find it handy that I can have a custom parser dedicated to a type but agnostic of default values; that also lets me use the same parser for multiple options with different default values. If the properties were merged again, then I'd instead have to make the parser method take the default value as a parameter, so its signature would no longer match that of the delegate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to the release of System.CommandLine 2.0.0, we found a number of things about the
Argument/Option.CustomParserandArgument/Option.DefaultValueFactoryAPI design to be awkward.They have nearly identical signatures but one (
DefaultValueFactory) is called only when no tokens are matched for the symbol, while the other (CustomParser) is called only when tokens are matched for the symbol. This was a regression from the original design where custom parsers were able to fulfill both of these roles at once. With the current API, if you want to use the same logic for both of these cases, you need to assign the same delegate to both properties.The goal of this proposed API is to unify this functionality and, hopefully, to make the usage clearer.
Please let me know what you think. Alternative proposals are welcome. Consider this PR an example to start conversation over how to improve this area of the System.CommandLine API.