Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line Parser Library parsing a List of Enums

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

like image 680
MaiOM Avatar asked Oct 15 '25 11:10

MaiOM


1 Answers

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
like image 180
stop-cran Avatar answered Oct 17 '25 05:10

stop-cran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!