The OptionList attribute allows you to specify several parts in the content of an option value. These parts are separated by a character (System.Char) of your choice.
Suppose we define a parsing target type like the following.


class Options
    // ...
    [OptionList("k", "keywords", Separator = ':', HelpText = "Specify keywords to search the text, separated by a colon.")]
    public IList<string> Keywords { get; set; };
    // ...	

As for Option[Attribute] you can see short and long name defined (and option help text). The Separator character, also available as a constructor parameter, will be the delimiter of the parts.
After a successful parsing, you'll get a List<string> instance setted in Options.Keyworkds. Each element will contain a part of the value.

The following will be accepted.


GuideApp -kapple:pear:banana

GuideApp -k coconut

GuideApp --keywords=banana:coconut:kiwi:orange

In the latter case we can read the parts as follows.


var options = new Options;
// ... here the parsing process ... 
foreach (string keyword in options.Keywords)

The following will be refused (or will not work as expected).


GuideApp -k

GuideApp --keywords = banana : coconut: kiwi : orange

GuideApp -k kiwi:orange banana:pear

Last edited May 15, 2012 at 8:13 AM by gsscoder, version 7


igitur Jun 25, 2014 at 7:15 AM 
I'm also interested in OptionArrays and OptionLists of types other than string.

roederja Feb 20, 2013 at 12:24 PM 
Can this be extended to also support lists of ints or Dates ?

gsscoder May 14, 2012 at 8:43 PM 

amissico Mar 29, 2010 at 10:20 PM 
What is the default character for the Separator?