C# Command Line Parser Library Example

01 Sep

Command Line Parser Library allows CLR applications to define a syntax for parsing command line arguments. It is very easy to incorporate this library into your C# project.

To install Command Line Parser Library, run the following command in the Package Manager Console:

PM> Install-Package CommandLineParser

Create a new class called CmdOptions, where the command line arguments are model with class properties:

image   image

To consume the command line argument:

    static void Main(string[] args)
           CmdOptions ops=new CmdOptions();
           bool bSuccess = CommandLine.Parser.Default.ParseArguments(args, ops);
           if (bSuccess)
              Console.WriteLine(ops.InputPhrase, ops.FontName);
              Console.Write(CmdOptions.HelpInfo); //output help strings

Running this app with no argument, and the result shows the help string in CmdOptions class:


So simple to use! Enjoy~

1 Comment

Posted by on September 1, 2013 in Dotnet/C#, Programming


Tags: , , , , , ,

One response to “C# Command Line Parser Library Example

  1. Robert

    February 8, 2017 at 1:43 am

    This helped me out just enough to keep moving forward – thanks


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: