command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

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

Open ElegantCat-nocat opened this issue 1 month ago • 0 comments

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 [email protected]

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

ElegantCat-nocat avatar Nov 26 '25 07:11 ElegantCat-nocat