commandlineparser / commandlineparser/commandline
FormatCommandLine function doesn't format Enum objects correctly
- 主要言語
- C#
- スター
- 4.8k
- フォーク
- 478
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
When passing in an object that has Enum parameters into the unparsing function FormatCommandLine, if the specified Enum has a value of 0, it does not successfully unparse into a string. I am currently using 2.8.0 of the CommandLineParser
For example:
```
public enum SomeEnumType
{
AValue,
AnotherValue
}
```
And you have an object:
```
[Verb("some-verb")]
public class SomeObject
{
[Option("some-attribute", Required = true)]
public SomeEnumType SomeAttribute { get; set; }
}
```
And you attempt to unparse it as such:
```
public class Program
{
static void Main(string[] args)
{
var stringArgs = Parser.Default.FormatCommandLine(new SomeObject
{
SomeAttribute = SomeEnumType.AValue
});
Console.WriteLine(stringArgs); // output: some-verb
var stringArgs2 = Parser.Default.FormatCommandLine(new SomeObject
{
SomeAttribute = SomeEnumType.AnotherValue
});
Console.WriteLine(stringArgs2);// output: some-verb --some-attribute AnotherValue
}
}
```
The workaround is to either add an Unspecified at the very beginning, or set AValue = 1 and Another Value = 2:
```
public enum SomeEnumType
{
AValue = 1,
AnotherValue = 2
}
```
or
```
public enum SomeEnumType
{
Unspecified,
AValue,
AnotherValue
}
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。