CSharpOptParse Position in the console X coordinate Y coordinate Constructor Rectangle in the console Left edge Top edge Right edge Bottom edge Information on the current screen buffer Size of the screen buffer Position of the cursor on the screen Attributes Bounds of the window Maximum window size Class to help with more advanced console functions Cosntructor Set the cursor position Get the current screen information Get the cursor position Define that a property or field can be given as an option For the property or field must have be type of bool For the property or field must be a integer For or the property or field must be the type of the property. For the property or field must be an of values of the type defined by the property (IList cannot be null). Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor The type of value the option takes or null to use the type of the property/field Get or set the type of value to support For most properties and fields, this is optional (can be left null), but for IList types of properties that take multiple values, this property needs to be set to know how to convert the command-line values to the type the list expects Get the type of value the option takes Gives the ability to stop the name of a field or property being used to be used as an option name By default, the name of a property or field is used as a option name when defined as an option (see ). This attribute allows only names to be given using and attributes. If this attribute value is false, one of the above attributes must be given for the property Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor Set to false to not use this field or property as a possible option name Get if the name should be used as an option Defines a long option for a field or property This is only applicable if the field or property is marked as an option using Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor Name of the option Get the name of the option Defines a short option name for a field or property This is only applicable if the field or property is marked as an option using Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor Name of the option Get the name of the option A simple, default implementation of that is fairly easy to use Interface for the parser to use to be able to print usage information for the given program. The usage structure is similar to the Perl POD structure, of headers with description blocks. The implementation however is not as robust. Check if a given header should contain the usage of the options The header to check True if the contents of this header is the options description Get the contents of a non-option header The header to get the contents for The contents for the header Get a list of all the "topic" headers for the usage Each header is similar to a header in a Unix man page. The header is a title block for the contents to follow. The usage information is broken up into sections, each started with a header. Typical headers are "Description", "Synopsis", "Options", "Arguments" Constructor to make argument description construction easier The argumentDescriptions array should be an even length. The event indexes (0, 2, 4, etc.) should be the argument names, and the odd indexes are the descriptions of the names (1, 3, etc. where 1 is the description of 0, 3 of 2, etc.). Example: new DefaultUsageInfo("HelloWorld.exe", "Says hello world with the arguments", "Additional text", "Text to print after saying hello world"); The name of the program (something.exe) Description of the program True to use all-upper case headers, or false for title cased headers list of descriptions in the format of { "Argument", "Description" [, "Argument", "Description"] ...} Constructor The name of the program (something.exe) Description of the program True to use all-upper case headers, or false for title cased headers Argument name, argument description pairs to describe the arguments the program takes or null if none Get if the given header should hold the option description The header True if the options header Get the contents of the given header Get the headers for the usage Delegate to receive warning events from a parser Define the behavior of the parser if an option is given that is not reconginzed Do not do anything, the option will be considered an argument A warning will be sent back to the caller of the parser (see the event) Stop parsing, throwing a Define the behavior of the parser if an option is duplicated If the option is not defined as a option that allows multiple values, then this enumeration specifies the action to take when a duplicate option is given at the command-line. Allow the duplicate declaration, using the last declaration to specify the value Allow the duplicate declaration, using the last declaration to specify the value, but send a warning back to the caller of the parser (see the event) Deny the duplicate declaration, throwing a The platform style of option Windows style of options (/opt) Use options in the standard Windows format. Example: program.exe /opt1:"Option 1 Value" /opt2:Opt2Value /opt3 Windows arguments do not differentiate between short an long formats like Unix arguments. Unix style of options (--opt, -o) Use options in the standard Unix format. Example: program --opt1="Option 1 Value" --opt2 Opt2Value -o Long argument values may be separated from the option by a space or by an equal sign. Short option values are separated from the option by a space Specify how short options may be given for Unix-style arguments Allow short arguments to be collapsed. Example: Program -abcd 0 "This is d's value" If the options require a value (See enum), then the the values after the arguments will be applied in order. Optional arguments that precede required arguments become required, meaning that if 3 values are given for 4 values (i.e. program -abcd val1 val2 val3), and the first two arguments have optional values, and the 3rd is required, and the fourth takes an optional value, then per the example, the value of 'val1' will be assigned to 'a', 'val2' to 'b', and 'val3' to 'c' with 'd' not having a value. Short options must be separated, and values do not need a space after the name Example: program -a -b -c0 -d"This is d's value" Type of value that the option permits The option does not accept a value The option does not accept a value, but may be declared multiple times This type of argument supports multiple declaration. For example, --verbose --verbose --verbose, could be used to allow a 3rd level of verbose information to be printed by a program. The option requires a value. If a value is not supplied, an error will be thrown The option optional takes a value The option allows 0 to many values Class that assists with reading values for enumeration values Get the field description for the enumeration value Enumeration: public enum ExampleEnum { [EnumDescription("This is the first value")] FirstValue = 1, [EnumDescription("This is the second value")] SecondValue = 2 } Usage: string desc = EnumDescriptorReader.GetEnumFieldDescription(ExampleEnum.FirstValue); The enumeration value to get the description of The description, or if it has none, the name Gets all of the descriptions for the values in the given enumeration type. If a description attribute is not found, the enumeration field name will be returned as the description instead The enumeration type An array of the descriptions. Exception thrown if the parser encounters an error Constructor Description of the error that occurred while parsing Constructor Exception that was thrown during parsing Constructor Description of the error that occurred while parsing Exception that was thrown during parsing Constructor for serialization. See Parsing exception that is thrown if a value is given that is not of the expected type Constructor Description of the error that occurred while parsing Constructor Exception that was thrown during parsing Constructor Description of the error that occurred while parsing Exception that was thrown during parsing Constructor for serialization. See Interface that describes an object that contains option definitions Get all of the options Array of option definitions Interface for interacting with the results of parsing the options This interface allows for storing option results in different formats. The class uses this interface. The implementation of this interface should be able to index the option definitions in both a case sensitive and case insensitive format. The parser's settings will determine the case sesitivity that will be used. Get the ID of the option for the provided short name The short name of the option to get the ID of If the option name's case should be considered The definition of the option or null if there is no option defined for the given name Get the ID of the option for the provided name The long name of the option to get the ID of If the option name's case should be considered The definition of the option or null if there is no option defined for the given name Get or set the result of an option by its definition Definition of an option Use this class to define possible options for a command-line. This is an alternative to using a class with fields and properties defined as options. Helper method to create OptionDefinition instances for each string in definitions Definitions (See ) OptionDefinition instances Build an option from a Perl-like string syntax The definition must match the following regular expression syntax: ^[\w|]+([:=+][sifd]?)?$. Explanation: Part Description [\w|]+ A series of one or more word or character names separated by pipe ('|') characters. Example: help|h|?. In this example, for Unix-style options, the valid option variations would be: --help, -h or -? [:=+] A character to define the type of value expected. This is optional, and if not given, the option will be considered a flag. So a definition of help can be given at the command-line like: Program --help. The ':' and '=' requires the type of value (see below). The '+' can be used in two ways. First, it can mean that a flag can be given multiple times (to be counted for example). This usage: verbose+ can be given like: Program --verbose --verbose --verbose to result in a verbosity of 3. With a type of value (see below), it means that the option can have many values. A value of ':' means the option may take a value, and '=' means that a value is required for this option. [sifd]? A character to define the type of data to accept. This is optional if the preceding character is '+' (see above). If given, the values map to the following .NET types: s - String, i - Int32, d - Double and f - Float Examples: Flag: Example show help: help|h|? Flag that gets counted: Example to set level of verbosity: verbose|v+ Option with a required string value (Example: set an output directory): Example to set an output directory: directory|dir|d=s Option with an optional integer value: Example to count value that defaults to 0: count|c:i Option that accepts multiple string values: Example to specify include patters: include|i+s The option definition Constructor ID of the option Option value type User-friendly description of the option The short name to map to this option the type of value that the option supports (if values are supported, ignored otherwise) Constructor ID of the option Option value type User-friendly description of the option The short names to map to this option the type of value that the option supports (if values are supported, ignored otherwise) Constructor ID of the option Option value type the type of value that the option supports (if values are supported, ignored otherwise) User-friendly description of the option The long name to map to this option Constructor ID of the option Option value type the type of value that the option supports (if values are supported, ignored otherwise) User-friendly description of the option The long names to map to this option Constructor ID of the option Option value type the type of value that the option supports (if values are supported, ignored otherwise) User-friendly description of the option The long names to map to this option The short names to map to this option Constructor ID of the option Option value type the type of value that the option supports (if values are supported, ignored otherwise) Category to use to group options when printing User-friendly description of the option The long names to map to this option The short names to map to this option Try to convert a given value to the value that this option supports The value given Thrown if the value could not be converted The converted value or null if the value could not be converted See See Produce a string version of this variable Default value of the option Get or set the category of the option Categories can be used to group the options when the usage is printed using the Get the type of value that the option supports (if values are supported) Get the type of value the option takes Get the short names for this option Null if short names are not supported by this option Get the ID for this option Allows an option to be identified if multiple names are used to define this option Get the user-friendly description of this option Get the long names for this option Null if long names are not supported by this option Stores the information on the result of parsing an option Constructor Definition of the option this result if for Add a value The value should already be converted to the correct type The value to add Get the definition for this result Get or set the number of times this option was defined If the type of the option supports multiple definitions or multiple values, then this property specifies how many times the option was defined Get if this property has been defined Get or set the value of the option This value will always be null for style arguments and may be null for and options. If the option is defined multiple times, this will get or set the first value given Get or set all the values given for this option This property allows access to all the values of the option for use with type of options Dictionary of option results When using the , the helper will use this class to store the results of option parsing in an instance of this class. Add a result Option definition Result value Validate the type of the key and value Update the inner index hashtables Update the inner index hashtables Update the inner index hashtables Update the inner index hashtables Get or set result by definition Get the result by the ID of a definition Class that parses option results into a dictionary interface The results are populated as {Key:[OptionDefinition] Value:[OptionResult]} pairs Constructor The supported options The dictionary that will be used to store the values of the options See See See See Helper class for the parser that stores values into properties and fields of a class. Used to create option definitions from properties and fields of an object. Options are defined using , , , , , , and attributes. Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor The object with the properties and fields defined as options See See See See Class that parses the command line options. Use the to construct an instance of a parser Class that Example class implementing options via attributes: // Example class defining properties class Properties { #region Enumerations internal enum ExamplePropertyEnum { First, Second } #endregion Enumerations #region Members private ExamplePropertyEnum _exampleEnumProp; #endregion Members #region Accessed by code properties // Cannot be used by the parser easily, but can be used // by code public ExamplePropertyEnum ExampleEnumProp { get { return _exampleEnumProp; } set { _exampleEnumProp = value; } } #endregion Accessed by code properties #region Options // Cannot be used by the parser easily, but can be used // by code // The EditorBrowsableAttribute is used to hide this // property from code [OptDef(OptValType.Flag)] [LongOptionName("example-enum-prop")] [UseNameAsLongOption(false)] [Description("Show how to perform complex type option parsing")] [EditorBrowsable(EditorBrowsableState.Never)] public string ExampleEnumPropAsString { get { return _exampleEnumProp.ToString(); } set { switch (value.ToLower()) { case "first": _exampleEnumProp = ExamplePropertyEnum.First; break; case "second": _exampleEnumProp = ExamplePropertyEnum.Second; break; default: throw new ArgumentException( "Invalid value for the example-enum-prop option"); } } } // Example of how to reverse flag-option values [OptDef(OptValType.Flag)] [LongOptionName("no-debug")] [UseNameAsLongOption(false)] [Description("Disable debug output")] [EditorBrowsable(EditorBrowsableState.Never)] public bool NoDebug { get { return !this.Debug; } set { this.Debug = !value; } } [ShortOptionName('b')] [OptDef(OptValType.Flag)] [LongOptionName("debug")] [UseNameAsLongOption(false)] [Description("Enable debug output")] public bool Debug = false; [OptDef(OptValType.ValueReq)] [ShortOptionName('d')] [LongOptionName("directory")] [UseNameAsLongOption(false)] [Description("Output directory")] [DefaultValue(".")] public string Directory = "."; [OptDef(OptValType.ValueOpt)] [ShortOptionName('f')] [LongOptionName("file")] [UseNameAsLongOption(false)] [Description("Input file")] public string File = null; [OptDef(OptValType.IncrementalFlag)] [ShortOptionName('v')] [LongOptionName("verbose")] [UseNameAsLongOption(false)] [Description("Set level of vebosity for debug printing")] public int Verbose = 0; [OptDef(OptValType.MultValue, ValueType=typeof(string))] [ShortOptionName('s')] [LongOptionName("strings")] [UseNameAsLongOption(false)] [Description("Test option that takes multiple values")] public StringCollection Strings = new StringCollection(); #endregion Options } Constructor The object is resposible for maintaining the option definitions and stores the results of parsing. The class can assist with constructing instances of the parser (handles object creating). If the factory is not used, the and classes can be used. The interface containing the option definitions and handles the results of parsing. Get all of the option definitions that have been declared Array of option definitions Get a collection of option value, option description pairs Used to help print the usage of the application. This function concatinates the options together into one string that is used as the key of the collection, and then sets the value as the description of the option. Example result: Key : -h, --help Value: Print the usage of this application Here, the key is a comma concatination of the options and the value is the description of that option. Short names will precede the long options in the key. The style of options. During concatination, the appropriate prefix ('/', '-' or '--') will be added to each option name Collection of the options and their descriptions Prints out the usage of this program to the given text writer Prints the usage to the standard output. See and for more information on how the usage is printed. At this time, wrapping is not done at word boundries The style of the options to have printed in the usage The number of columns to print before wrapping the text. Used to correctly format the indenting Prints out the usage of this program to the given text writer Prints the usage to the given writer. See and for more information on how the usage is printed. At this time, wrapping is not done at word boundries The style of the options to have printed in the usage The writer to print the usage to The number of columns to print before wrapping the text. Used to correctly format the indenting Parse the for options using the parser settings Arguments from the command-line that were not options Parse the arguments for options using the parser settings The command-line arguments to parse Arguments from the command-line that were not options Parse the arguments for options using the given settings What type of options to parse How to parse unix short options (ignored if not unix style parsing) How to handle un-expected duplicate option definitions How to handle options that were not defined If the parsing of options should consider the case of the options The command-line arguments to parse Arguments from the command-line that were not options Prints text to the given writer with the given indent At this time wrapping is not done at a word boundry The indent to add to the text in terms of number of spaces The text to print The number of columns to wrap at The writer to print to Parse a concatinated list of short options All the arguments The options found The current index in the arguments which can be incremented by this function How to handle un-expected duplicate option definitions How to handle options that were not defined True if parsing is case-sensitive The option definitions already found An array of all unknown option characters or null if all were known Parse a short option All the arguments The option name found The value immediately following the option (no space) The current index in the arguments which can be incremented by this function How to handle un-expected duplicate option definitions How to handle options that were not defined True if parsing is case-sensitive The option definitions already found If the option was unknown and the handle type was not error, this will be true so that the "option" can be added to the arguments Parse a long option All the arguments The option name found The value immediately following the option ([=:]value syntax) The current index in the arguments which can be incremented by this function How to handle un-expected duplicate option definitions How to handle options that were not defined True if parsing is case-sensitive The option definitions already found If the option was unknown and the handle type was not error, this will be true so that the "option" can be added to the arguments Parse an option All the arguments The char or string that the option was identified with The option found The value immediately following the option ([=:]value syntax) The current index in the arguments which can be incremented by this function How to handle un-expected duplicate option definitions How to handle options that were not defined The option definitions already found If the option was unknown and the handle type was not error, this will be true so that the "option" can be added to the arguments Check if the option is a duplicate (2nd, 3rd, etc. declaration) and the option does not support multiple values/declarations The option found All of the found definitions so far How to handle duplicates True if the option has already been found, and the type does not support duplicates Check if the option definition does not allow a value and if a value was given The option definition The value given or null if one was not given Thrown if value was given to a type that doesn't support a value Get the options defined for this parser All of the defined options Event fired when a warning event occurs Get or set to search the environment names for values to the options If set to true, environment variable values will be used if found and the options are not given on the command line. The prefixes (--, -, or /) are not used, only the names of the options when searching the environment. Get or set if the parsing of options should consider the case of the options Get or set how the parser should handle un-expected duplicate option declarations Get the handler for the parser Get or set the option style to parse Get or set how to handle unknown options Get how to handle short unix options (with or without bundling) Event args for parse warnings Constructor The warning message Get the warning message Factory to build parser instances Build a parser Object containing fields and properties that represent option definitions Parser instance Build a parser The supported options Dictionary to recieve parsed option values Parser instance Build a parser The supported options The dictionary to store the option results in Parser instance Build a parser using a custom handler. Custom handler Parser instance Type of list to create in the usage Numbered/ordered list Unordered list Class to assist the building of program usage information The API of this class is similar to that of an . The output of the usage is an . The using the , and methods the XML can be transformed into the desired output format for the usage. Example code printing different usage outputs: UsageBuilder usage = new UsageBuilder(); usage.GroupOptionsByCategory = false; usage.BeginSection("Name"); usage.AddParagraph("Tester.exe"); usage.EndSection(); usage.BeginSection("Synopsis"); usage.AddParagraph("Tester.exe [options] [arguments]"); usage.EndSection(); usage.BeginSection("Description"); usage.AddParagraph("Program to test the CSharpOptParse library"); // List of bullets usage.BeginList(ListType.Unordered); usage.AddListItem("First"); usage.AddListItem("Second"); usage.EndList(); // Example of creating nested lists: usage.AddParagraph("Test"); usage.BeginList(ListType.Ordered); usage.AddListItem("First"); usage.BeginList(ListType.Ordered); usage.AddListItem("Item"); usage.BeginList(ListType.Ordered); usage.AddListItem("Item"); usage.BeginList(ListType.Ordered); usage.AddListItem("Item"); usage.EndList(); usage.EndList(); usage.EndList(); usage.AddListItem("Second"); usage.EndList(); usage.EndSection(); usage.BeginSection("Options"); usage.AddOptions(parser); // parser is an instance of Parser usage.EndSection(); usage.BeginSection("Arguments"); usage.AddParagraph("Before arguments"); usage.BeginArguments(); usage.AddArgument("Arguments to pass through", "Arguments to check if the parsing is returning the correct number of arguments", typeof(string), true); usage.EndArguments(); usage.AddParagraph("After arguments"); usage.EndSection(); using (StreamWriter sw = new StreamWriter("Usage.html")) { usage.ToHtml(sw, OptStyle.Unix, null, true, "Tester.exe"); } Console.WriteLine("Usage:"); usage.ToText(Console.Out, OptStyle.Unix, true); Default constructor Convenience method for transforming the XML using a custom XSLT TextWriter to write the output to Xslt content to use to transform with Xslt arguments to pass to the Convert the usage to HTML TextWriter to write the output to The style to use when printing possible option names Stylesheet URI to apply to the HTML content True to include the default option values in the output Title to use for the HTML page Convert the usage to Text TextWriter to write the output to The style to use when printing possible option names True to include the default option values in the output Convert the usage to Text if is -1, the width of the console will be used on windows machines, and the text will not be wrapped on non-windows machines TextWriter to write the output to The style to use when printing possible option names True to include the default option values in the output Wrap text at the given column (attempts to wrap at '-' or ' ') Begin a new section tag May only be under a "usage" or "section" tag. must be called to close this tag Name of the section Close the section Section tag must be active Add a paragraph to the usage May only be inside of "section" or "description" tags The body of the paragraph Add a paragraph to the usage May only be inside of "section" or "description" tags. must be called to close this tag. Use to add text to the paragraph body. Add content to the current paragraph node May only be called when a "para" tag is active. Text to add Close the active "para" tag May only be called when a "para" tag is active. Open a list tag Sets the active tag to a new "list" tag. May only be called when one of the following tags are active: "section", "paragraph", "list", "description". must be called to close this tag The type of list Add a list item tag to the current list May only be called when a "list" tag is active. Body of the list item to add Close the active "list" tag May only be called when a "list" tag is active. Begin an active "options" tag May only be called when a "header" tag is active. Close the active "options" tag May only be called when a "options" tag is active. Method to start adding an option to the usage. Leaves the "description" tag as the active tag. Allows paragraph and list content to be added to the description of an option beyond the normal description. Does not include the description body from the (must be added manually). Call to close this tag. Option to start Close the active "description" tag and "option" tags May only be called when a "description" tag is active below an "option" tag. Add multiple options to the output Can only be called if the active tag is "section" Container with all the options for the program to document Add multiple options to the output Can only be called if the active tag is "section" All the options for the program Adds an option to the output Like , but uses the desription from the option as the body of the "description" tag. Does not open a new active tag Option to add Begin an active "arguments" tag May only be called when a "header" tag is active. Close the active "arguments" tag May only be called when an "arguments" tag is active. Add an argument overview to the usage Can only be called when a "section" tag is active. Does not leave a new active tag open. Short name description of the argument Description of the argument Supported data type for the argument (typeof(string) is usually the best choice). True if the argument should be marked as optional Add an argument overview to the usage Can only be called when an "arguments" tag is active. Leaves the "description" tag active under the "argument" tag. Short name description of the argument Supported data type for the argument (typeof(string) is usually the best choice). True if the argument should be marked as optional Close the active "description" tag and "argument" tags May only be called when a "description" tag is active below an "argument" tag. Get the containing the usage content Get or set the category to use for options when an option is missing a category Cannot be set to null or an empty string, if so, the default value will be used Get or set to group options by their categories Class to help with Text transformation Constructor Column to wrap at Create a string of spaces Length of the string to create The string Formats text, adding indent and wrapping lines Text to format Indent to add to each line Additional indent to add to lines after the first Formatted text