commandline icon indicating copy to clipboard operation
commandline copied to clipboard

nullable enums

Open tofutim opened this issue 9 years ago • 1 comments

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.

tofutim avatar Aug 17 '16 18:08 tofutim

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

SuperJMN avatar Oct 22 '17 16:10 SuperJMN