Added support in OptionList for numerous arguments of a single type

Nov 5, 2012 at 3:06 PM
Edited Nov 5, 2012 at 4:42 PM

I added functionality that I felt might be useful to add into the actual library. Very very simple change.

Essentially what I wanted was the ability to have multiple arguments of the same type and compile them into a list. So instead of having:

-o Option1:Option2:Option3

It can also now do:

-o Option1 -o Option2 -o Option3

This allows me to make dynamic argument creation much easier. I have a dynamic process that can load modules which may take arguments of their own. So instead of having to combine all of their own arguments into a single -o argument and then further parse it I can make it so that an argument for one module might use

-omodule1:nestedargument1 -omodule2:nestedargument2

All I did was alter SetValueList in OptionInfo. Instead of just having this line _property.SetValue(options, new List<string>(), null); which will continually reinitialize the property. Instead I check to see if the value is null, if it is, it initializes it with that same line, otherwise it skips the initialization.

var currentValue = _property.GetValue(options, null);
if (currentValue == null)
     _property.SetValue(options, new List<string>(), null);


Works great for me. Thanks.

Feb 24, 2013 at 5:03 AM
Thanks to you @TRJG,

This is interesting and will be evaluated.

Actually specialized attributes use separators for comply standard way of defining arguments in *nix shell.

Anyway I liked suggestion, but I think it should be explicited using a normal option:
class Options {

  [Option('m', AllowMultiple=true)]
  public IEnumerable<string> ModuleToLoad { get; set; }
app -m Some.dll -m Other.dll -m To.dll -m Load.dll
Please let me reason about it. Suggestion are always welcome, good suggestions like this even more! :))

Regards, Giacomo

PS: to know when some cool suggestion is implemented (and this happens very often) -> follow me on Twitter -> @gsscoder