4

I'm trying to get a list of enums as an option.

[OptionList('m', "modules", HelpText = "List of modules you are going to install or uninstall.")]
public List<RegistrationType> Modules { get; set; }

Unfortunately it expects it to be a list of strings. Any idea on how to make it work as documentation of the lib is a bit short.

Thanks

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
MaiOM
  • 916
  • 2
  • 13
  • 28
  • Just ran into this one too. Documentation says enums are supported but complains about converting from string. – Pxtl Nov 17 '16 at 20:20

2 Answers2

4

As of Nov 2018, there is a support for IEnumerable<TEnum> (package version 2.3.0):

[Option('m', "modules", Separator = ',', HelpText = "List of modules...")]
public IEnumerable<RegistrationType> Modules { get; set; }

Sample parse (has changed since the question was asked):

static void Main(string[] args)
{
    Parser.Default.ParseArguments<Options>(args)
        .WithParsed(options => ...)
}

Sample command line:

myProject.exe -m RegistrationType1,RegistrationType2
stop-cran
  • 4,229
  • 2
  • 30
  • 47
-1

Unfortunately, it doesn't support any list other than IList. Any type but string :(

Sorry. It seems that this library is very powerful, but has very little documentation about it.

SuperJMN
  • 13,110
  • 16
  • 86
  • 185