Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Argument and Option classes abstract #1638

Closed
jonsequitur opened this issue Feb 12, 2022 · 0 comments
Closed

Make Argument and Option classes abstract #1638

jonsequitur opened this issue Feb 12, 2022 · 0 comments
Assignees
Labels
Breaking Change needs discussion Further discussion required
Milestone

Comments

@jonsequitur
Copy link
Contributor

jonsequitur commented Feb 12, 2022

The Option class can currently be instantiated as follows. (Argument is similar so for the purpose of this issue, I'll only talk about Option, but the change would apply to both.)

var option = new Option("-x");
option.ValueType = typeof(int);

By default, the ValueType for Option is string.

This is largely equivalent to instantiating an Option<int>, and the following will return an int (as a compile-time object):

var value = parseResult.FindResultFor(option).GetValueOrDefault();

The non-generic Option can also be late-bound like this:

var value = parseResult.FindResultFor(option).GetValueOrDefault<int>();

This capability wasn't removed because of scenarios where parsers might be built based on a runtime reflection-dependent model, such as attribute-based app models. Forcing use of the generic types was potentially awkward here. As source generation has become more common and as we look to make the library more performant, the use case has become less compelling and the performance and complexity cost less worthwhile.

They are still needed though as base type, e.g. for the Command.Options collection.

@jonsequitur jonsequitur added this to the 2.0 GA milestone Feb 12, 2022
@jonsequitur jonsequitur added needs discussion Further discussion required Breaking Change labels Feb 12, 2022
@jonsequitur jonsequitur changed the title Consider removing non-generic Argument and Option classes Argument and Option classes: consider making them abstract or removing them Feb 12, 2022
@jonsequitur jonsequitur changed the title Argument and Option classes: consider making them abstract or removing them Consider making Argument and Option classes abstract Feb 12, 2022
@jonsequitur jonsequitur self-assigned this Mar 12, 2022
@jonsequitur jonsequitur changed the title Consider making Argument and Option classes abstract Make Argument and Option classes abstract Mar 15, 2022
@jonsequitur jonsequitur mentioned this issue Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change needs discussion Further discussion required
Projects
None yet
Development

No branches or pull requests

1 participant