Skip to content

Make Argument and Option classes abstract #1638

Closed
@jonsequitur

Description

@jonsequitur

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions