Command Line Processing

Despite the popularity of application servers and single page web apps, there are still times when a simple console
application is the easiest - and best - way to solve some kinds of problems.

I’ve published an open-source project to GitHub to make it easier to write these console
applications by providing a simple convention based approach for handling the command line parameters. This project
is also available through nuget for simple use.

For a simple switch, write a method that takes no parameters and returns no value. Decorate it with [Description] to
opt-in for handling as a switch. The name of the method is used to define a pair of flags for the command line.

[Description("Provide help on available parameters.")]// This method defines -h and --help
publicvoidHelp(){...}

For a parameter that takes a single value, write a method that takes one parameter and returns no value. Again, you ‘
must decorate it with [Description] to opt-in for handling as a parameter, and the name of the method is used to
define a pair of flags.

[Description("Specify the output file to write.")]// This method defiles -of and --output-file
publicvoidOutputFile(stringfileName){...}

For a parameter that can be specified multiple times, write a method that takes a sequence of values and returns no
value. Again, you ‘
must decorate it with [Description] to opt-in for handling as a parameter, and the name of the method is used to
define a pair of flags.

[Description("Specify a file to process.")]// This method defiles -rf and --read-file
publicvoidReadFile(IEnumerable<string>fileName){...}