commandlineparser / commandlineparser/commandline

FormatCommandLine function doesn't format Enum objects correctly

Abierto
#710 1 comentario 2 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C#
Estrellas
4.8k
Forks
478
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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
}
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.