Skip to content

Commit b658ec0

Browse files
committed
fix #2743
1 parent e744336 commit b658ec0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/System.CommandLine.Tests/CustomParsingTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,23 @@ public void Custom_parser_is_called_once_per_parse_operation_when_input_is_provi
561561
i.Should().Be(2);
562562
}
563563

564+
[Fact] // https://github.com/dotnet/command-line-api/issues/2743
565+
public void Setting_CustomParser_to_null_reverts_to_default_parsing()
566+
{
567+
Argument<int> argument = new("int")
568+
{
569+
CustomParser = (_) => 0
570+
};
571+
572+
argument.CustomParser = null;
573+
574+
var command = new RootCommand { argument };
575+
576+
var result = command.Parse("123");
577+
578+
result.GetValue(argument).Should().Be(123);
579+
}
580+
564581
[Fact]
565582
public void Default_value_factory_is_called_once_per_parse_operation_when_no_input_is_provided()
566583
{

src/System.CommandLine/Argument{T}.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public Func<ArgumentResult, T>? DefaultValueFactory
7878
}
7979
};
8080
}
81+
else
82+
{
83+
ConvertArguments = null;
84+
}
8185
}
8286
}
8387

0 commit comments

Comments
 (0)