From c48ffbc5410f12c29c0398b9cd47726c5a0156ff Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Mon, 18 Jan 2021 19:43:32 +0800 Subject: [PATCH] Should set UnderlyingType when use Template --- src/CommandLineUtils/Attributes/OptionAttribute.cs | 3 ++- .../CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/CommandLineUtils/Attributes/OptionAttribute.cs b/src/CommandLineUtils/Attributes/OptionAttribute.cs index 6f7e1ac9..bf6b0b58 100755 --- a/src/CommandLineUtils/Attributes/OptionAttribute.cs +++ b/src/CommandLineUtils/Attributes/OptionAttribute.cs @@ -82,10 +82,11 @@ internal CommandOption Configure(CommandLineApplication app, PropertyInfo prop) LongName = longName, ShortName = longName.Substring(0, 1), ValueName = prop.Name.ToConstantCase(), - UnderlyingType = prop.PropertyType, }; } + option.UnderlyingType = prop.PropertyType; + Configure(option); option.Description ??= prop.Name; diff --git a/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs b/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs index f419fa8c..9fdd88b8 100644 --- a/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs +++ b/test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs @@ -216,6 +216,9 @@ SomeNullableEnumArgument nullable enum arg desc. Allowed values are: None, Normal, Extreme. -enumOpt4|--verb4[:] nullable enum option desc. Allowed values are: None, Normal, Extreme. + -enumOpt5|--verb5 enum option desc. + Allowed values are: None, Normal, Extreme. + Default value is: None. -?|-h|--help Show help information. ", @@ -255,6 +258,9 @@ public class MyApp [Option(CommandOptionType.SingleOrNoValue, ShortName = "enumOpt4", Description = "nullable enum option desc.")] public SomeEnum? Verb4 { get; set; } + [Option("-enumOpt5 | --verb5 ", Description = "enum option desc.")] + public SomeEnum Verb5 { get; set; } + [Argument(0, Description = "string arg desc.")] public string SomeStringArgument { get; set; }