Data Types Mapping

When you define the type that will store parsed values, you should consider the target data type of each option.

Using Strings

Since command line arguments comes from an array of strings, a string is capable of storing any input.

C#:

class Options
{
    // ...
    [Option("s", "string")]
    public string InputString { get; set; };
    // ...
}

Using an option as the one defined above, the following input (and not only) will be accepted.

Console:

GuideApp -s aString

GuideApp --string "a string"

GuideApp -s1alfa2numeric3

GuideApp --string=123

GuideApp --string 123.4


Note that the use of double quotes to pass a value containing spaces, is a shell prerogative and not a feature of this software.

Using Numbers

C#:

class Options
{
  public Options()
  {
    InputDouble = 13.9;
  }

  // ...
  [Option("d", "double")]
  public double InputDouble { get; set; };
  // ...
}

Because of recent design changes about using properties instead of fields, you should initialize numeric properties. Otherwise I suggest you use nullable types and expect null if the option is not required.

Using Enumerations

Enumerations are not different from numbers. If not initialized the first element will be property default.

Last edited May 14, 2012 at 9:03 PM by gsscoder, version 7

Comments

gsscoder May 14, 2012 at 8:56 PM 
Now the library ONLY supports properties from author design decisions and a lot of user requests.

juanalumni Oct 18, 2011 at 9:20 PM 
I agree, it should support properties with a setter also.
BTW, great tool!

SeenDaBean Dec 13, 2010 at 2:26 AM 
Who's idea was it to make the BaseOptionAttribute only support fields? I feel it's must better practices to allow fields and properties especially given C# 3.0+ which allows us to use properties with implictly defined backing fields. I'm now having to add a bunch of clutter to my options class to work around this odd limitation. Please fix!