Documentation for the C# command-line option parsing library

UsageBuilder Class

Class to assist the building of program usage information

For a list of all members of this type, see UsageBuilder Members.

System.Object
   CommandLine.OptParse.UsageBuilder

public class UsageBuilder

Remarks

The API of this class is similar to that of an XmlTextWriter. The output of the usage is an XmlDocument. The using the ToHtml, ToText and Transform methods the XML can be transformed into the desired output format for the usage.

Example

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);            
            

Requirements

Namespace: CommandLine.OptParse

Assembly: CSharpOptParse (in CSharpOptParse.dll)

See Also

UsageBuilder Members | CommandLine.OptParse Namespace