Skip to content

CustomParser of Argument<T> cannot be reset by setting to null #2743

@ElegantCat-nocat

Description

@ElegantCat-nocat

When I set the CustomParser property of an Argument<T> to a custom parser, and then set it back to null, the custom parser is still being used, instead of the default parser.

Code to reproduce:

#:package System.CommandLine@2.0.0

using System.CommandLine;

Argument<int> argument = new("int")
{
    CustomParser = (_) =>
    {
        Console.WriteLine("Using Custom Parser");
        return 0;
    }
};

argument.CustomParser = null;

RootCommand command = new()
{
    argument
};

var result = command.Parse("123");

Console.WriteLine(result.GetValue(argument));

Expected output:

123

Actual output:

Using Custom Parser
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions