Skip to content

Commit c48ffbc

Browse files
committed
Should set UnderlyingType when use Template
1 parent 85059ba commit c48ffbc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/CommandLineUtils/Attributes/OptionAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ internal CommandOption Configure(CommandLineApplication app, PropertyInfo prop)
8282
LongName = longName,
8383
ShortName = longName.Substring(0, 1),
8484
ValueName = prop.Name.ToConstantCase(),
85-
UnderlyingType = prop.PropertyType,
8685
};
8786
}
8887

88+
option.UnderlyingType = prop.PropertyType;
89+
8990
Configure(option);
9091

9192
option.Description ??= prop.Name;

test/CommandLineUtils.Tests/DefaultHelpTextGeneratorTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ SomeNullableEnumArgument nullable enum arg desc.
216216
Allowed values are: None, Normal, Extreme.
217217
-enumOpt4|--verb4[:<VERB4>] nullable enum option desc.
218218
Allowed values are: None, Normal, Extreme.
219+
-enumOpt5|--verb5 <VERB5> enum option desc.
220+
Allowed values are: None, Normal, Extreme.
221+
Default value is: None.
219222
-?|-h|--help Show help information.
220223
221224
",
@@ -255,6 +258,9 @@ public class MyApp
255258
[Option(CommandOptionType.SingleOrNoValue, ShortName = "enumOpt4", Description = "nullable enum option desc.")]
256259
public SomeEnum? Verb4 { get; set; }
257260

261+
[Option("-enumOpt5 | --verb5 <VERB5>", Description = "enum option desc.")]
262+
public SomeEnum Verb5 { get; set; }
263+
258264
[Argument(0, Description = "string arg desc.")]
259265
public string SomeStringArgument { get; set; }
260266

0 commit comments

Comments
 (0)