commandlineparser / commandlineparser/commandline
InvalidCastException when parsing nullable enum
- 主要语言
- C#
- 星标
- 4.8k
- 派生
- 478
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hi there,
my code looks like this:
```
// Code in Main
using (var parser = Parser.Default)
{
var parserResult = parser.ParseArguments(args);
}
// CommandlineOptions Class
public class CommandlineOptions
{
[Option('c', "command", Required = true, HelpText = "The Command to use")]
public ECommand? Command { get; set; }
}
// Enum ECommand
public enum ECommand
{
DoStuff = 1;
DoSomethingElse = 2;
}
```
Notice that my Command-Option is a nullable enum.
When i run my programm with the following command
`myProgramm.exe -c DoStuff`
I get an `InvalidCastException`, saying that it can't convert `System.String` in `ECommand`.
This exception is thrown by` parser.ParseArguments()`.
Am I missing something or is this a bug?
How can i fix that?
I know that the exception doesn't occure if the enum isn't nullable. But I need the nullable enum at that point!
Hope you can help me.
Greetings Tom
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。