Mono.Options 0.2.0.0 0.2.1.0 All members of this type are safe for multithreaded operations. Subclasses must be thread-safe if multithreaded invocation of is required. System.Object Represents information about an option.

Instances of are created via the various overloads, such as:

You can also add custom subclasses to an via the method.

Inheritors of this type must override the method , which is (indirectly) invoked from within when an option matching one of the aliases is encountered.
- Constructor
  0.2.0.0
  0.2.1.0
  A containing a |-separated list of option names (aliases) and an optional value-type specifier.
  A containing documentation for the option.
  Creates and initializes a new instance of the class.

  This constructor initializes the property of the new instance using , the property of the new instance using . and initializes the property of the new instance to 1.

  This is equivalent to calling the constructor as with Option(, , 1).

  is the empty string "".

  -or-

  contains an empty alias, such as a||b.

  -or-

  Conflicting values were found within .

  -or-

  only includes the default handler <> and did not specify an value of .

  is .
- Constructor
  0.2.0.0
  0.2.1.0
  A containing a |-separated list of option names (aliases) and an optional value-type specifier.
  A containing documentation for the option.
  A containing the number of values this option accepts.
  Creates and initializes a new instance of the class.

  This constructor initializes the property of the new instance using , the property of the new instance using . and initializes the property of the new instance using .

  is a |-separated list of option names. It should be listed in shortest-to-longest order, e.g. h|help. may contain a specifier following one of the |-separated entries, and a value separator list following the specifier.

  The property is initialized based on whether a = or : follows one of the aliases within . = specifies a value, while : specifies an value. If neither = nor : is not specified, then is used. The value specifier may be used anywhere within , so n|name=, n=|name and n=|name= are equivalent, but you cannot mix types; n:|name= is invalid.

  A default handler may be specified by using <> as the option name. The default handler is invoked for any unhandled argument within ; consequently, if a default handler is provided then will return an empty .

  The default handler may either be provided as a stand-alone , in which case it may not specify a other than . Alternatively, it may be an alias, in which case the must accept an or value, and must be 1.

  Multiple values may be bundled together, such as -opt key=value. The value separator list specifies which characters can be used to split the value argument to generate separate values. The value separator list is available when is greater than 1, and and an was specified. The value separator list follows the = or : and is one of the following:

  A sequence of character enclosed by { and }. Multiple such sequences may be specified by listing the {...} sequence multiple times.

  The sequence {} requires that each value be a different argument, and no argument splitting will be performed. This sequence has no effect if other separators are also listed (as separate arguments are always permitted for values).

  Any literal character other than { and }.

  If the separator list is not provided, then =: is the default separator list.

  For example, the prototype "A:+-*/" would permit any of `+', `-', `*', or `/' to be used to split an argument into values, so -A:5/2 would generate the sequence of values 5 and 2 for the option -A. Furthermore, the prototype "A={-->}{=>}" would permit either the string --> or the string => to be used, so -A A->B C woud parse A->B as one value and C as the other value, while -A A-->B C would parse A as one value and B as the other value while C would be unhandled (unless the option required 3 values, in which case C would be the 3rd value).

  is the empty string "".

  -or-

  contains an empty alias, such as a||b.

  -or-

  Conflicting values were found within .

  -or-

  is 0 and specified an value of or .

  -or-

  is greater than 1 and specified an value of .

  -or-

  contains a separator list and is 0 or 1.

  -or-

  contains a badly formatted separator list, such as {{, }}, {{}, etc.

  -or-

  only includes the default handler <> and did not specify an value of .

  -or-

  includes the default handler <>, and is greater than 1.

  is .
- Property
  0.2.0.0
  0.2.1.0
  System.String A containing documentation for this option. A containing documentation for this option. This property is used to generate documentation within . The string returned is translated via the parameter provided to the constructor before being written to the instance.
- Method
  0.2.0.0
  0.2.1.0
  System.String[] Retrieves all name aliases that make up . A array containing all name aliases for this instance. The returned option names will not contain any specifier that may be within . If is a=|b=|c=, the array returned will contain a, b, and c.
- Method
  0.2.0.0
  0.2.1.0
  System.String[] Retreives all value separators, strings which are used to split an argument into one or more values for the this . A array containing all strings that should be used when splitting an argument into one or more values for this .

  Value separators may be provided within only if:

  is greater than 1.
  is or .

  See the constructor for more information.

- Method
  0.2.0.0
  0.2.1.0
  System.Void `` An instance containing information about the option that was parsed. Invokes then clears out .

  This method is invoked from within when an option with a name from is encountered and matches the required number of values governed by and .

  This method invokes , passing along unchanged, and then sets the and properties to , and s out .

- Property
  0.2.0.0
  0.2.1.0
  System.Int32 A containing the maximum number of values this accepts. A containing the maximum number of values this accepts.

  This is a maximum, and may not be the number of values present within when is invoked. There will be values if is , but if is then may contain fewer items.

- Method
  0.2.0.0
  0.2.1.0
  System.Void `` An instance containing information about the option that was parsed. Perform an action when an option is parsed.

  This method must be overridden by all subclasses, within which the subclass can perform some custom per-option processing.

  This method is invoked from within when an option with a name from is encountered and matches the required number of values governed by and .

  The following example has a custom subclass which overrides :

  `// Case-Insensitive and Concatenating OptionSet using System; using System.Collections.Generic; using Mono.Options; class DemoOptionSet : OptionSet { protected override void InsertItem (int index, Option item) { if (item.Prototype.ToLower () != item.Prototype) throw new ArgumentException ("prototypes must be lower-case!"); base.InsertItem (index, item); } protected override OptionContext CreateOptionContext () { return new OptionContext (this); } protected override bool Parse (string option, OptionContext c) { string f, n, s, v; bool haveParts = GetOptionParts (option, out f, out n, out s, out v); Option nextOption = null; string newOption = option; if (haveParts) { string nl = n.ToLower (); nextOption = Contains (nl) ? this [nl] : null; newOption = f + n.ToLower () + (v != null ? s + v : ""); } if (c.Option != null) { // Prevent --a --b if (c.Option != null && haveParts) { if (nextOption == null) { // ignore } else throw new OptionException ( string.Format ("Found option `{0}' as value for option `{1}'.", option, c.OptionName), c.OptionName); } // have a option w/ required value; try to concat values. if (AppendValue (option, c)) { if (!option.EndsWith ("\\") && c.Option.MaxValueCount == c.OptionValues.Count) { c.Option.Invoke (c); } return true; } else base.Parse (newOption, c); } if (!haveParts || v == null) { // Not an option; let base handle as a non-option argument. return base.Parse (newOption, c); } if (nextOption.OptionValueType != OptionValueType.None && v.EndsWith ("\\")) { c.Option = nextOption; c.OptionValues.Add (v); c.OptionName = f + n; return true; } return base.Parse (newOption, c); } private bool AppendValue (string value, OptionContext c) { bool added = false; string[] seps = c.Option.GetValueSeparators (); foreach (var o in seps.Length != 0 ? value.Split (seps, StringSplitOptions.None) : new string[]{value}) { int idx = c.OptionValues.Count-1; if (idx == -1 || !c.OptionValues [idx].EndsWith ("\\")) { c.OptionValues.Add (o); added = true; } else { c.OptionValues [idx] += value; added = true; } } return added; } } class Demo { public static void Main (string[] args) { List<string> names = new List<string> (); Dictionary<string,string> map = new Dictionary<string,string> (); int repeat = 1; OptionSet p = new DemoOptionSet () { { "n|name=", v => names.Add (v) }, { "r|repeat:", (int v) => repeat = v }, { "m|map=", (k,v) => map.Add (k, v) }, }; List<string> extra; try { extra = p.Parse (args); } catch (OptionException e) { Console.Write ("subclass: "); Console.WriteLine (e.Message); return; } string message; if (extra.Count > 0) { message = string.Join (" ", extra.ToArray ()); } else { message = "Hello {0}!"; } foreach (string name in names) { for (int i = 0; i < repeat; ++i) Console.WriteLine (message, name); } List<string> keys = new List<string>(map.Keys); keys.Sort (); foreach (string key in keys) { Console.WriteLine ("Key: {0}={1}", key, map [key]); } } }`

  See for more on this example.

- Property
  0.2.0.0
  0.2.1.0
  Mono.Options.OptionValueType An instance specifying whether this takes a value, and if so, whether it's required or optional. An specifying whether a value is required for this value.

  This is initialized based on the presence of = or : within .

- Method
  0.2.0.0
  0.2.1.0
  T `` `` The type to convert the string to. A containing a representation of the type that should be converted into an instance of type . A containing additional contextual information needed error handling. Converts the into an object of type . If is , then is returned. Otherwise, is converted to a value of type .

  is used to get the associated with type , and is used to convert into a .

  If is not and generated an exception while trying to convert .
- Property
  0.2.0.0
  0.2.1.0
  System.String The prototype, containing option name aliases and the option value requirements. A containing the prototype of this instance.

  The prototype contains a |-separated list of all option name aliases and a value specifier of = for required values and : for optional values; if neither = nor : is present, no value is taken.

  If a value specifier is present, then a value separator list may also be present after the value specifier.

- Method
  0.2.0.0
  0.2.1.0
  System.String Returns . A containing .