Skip to content

Non-generic GetValueForOption does not work with boolean flag #1647

Closed
@einarmo

Description

@einarmo

Reproduction:

var opt = new Option<bool>(new[] { "-b" }, "Some description");

var cmd = new RootCommand
{
    opt
};

var res = cmd.Parse("-b");
Assert.True((bool)res.GetValueForOption((Option)opt));

It works if you pass "true", e.g. -b true, or if you use the generic method directly.

I ended up adding this code to work around the issue:

// Here I only know that opt is some Option<>

if (opt.GetType() == typeof(Option<>).MakeGenericType(typeof(bool)))
{
    res = bindingContext.ParseResult.GetValueForOption((Option<bool>)opt);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions