commandline
commandline copied to clipboard
nullable enums
Hi, I have an enum called LoggingLevel
public enum LoggingLevel
{
ALL,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
OFF
}
which gets mapped to an option which is a nullable LoggingLevel
[Option(HelpText = "Console logging level", DefaultValue =LoggingLevel.ALL)]
public LoggingLevel? ConsoleLevel { get; set; }
The effect I want is that if the option is not specified, then ConsoleLevel is null. But when it is specified, but no level is given, then it will be ALL. However, it doesn't really work.
--consolelevel gives me null, rather than ALL. Not specifying anything gives me null. If I switch so that ConsoleLevel is not nullable, then the defaultvalue gets set to ALL always.
Sorry, but the an enumerated type, the empty-none-off option should be the very first value in the enum. It should be:
public enum LoggingLevel
{
OFF
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
ALL,
}