Skip to main content

Posts

Showing posts from July, 2013

Parse and organize command line options using C#

This class will parse, organize and collect command line options. I couldn't find anything like it, so I wrote one. This works all the way down to .NET 1.1 if you are lucky enough to still be using that. Save this as ArgDictionary.cs, change the namespace as needed, and feel free to use it in your projects. using System; using System.Collections.Generic; namespace Utilities { /// /// Implements a Dictionary object for handling command line options. /// Supports options with prefixes -, --, or /. /// Supports Boolean, String, or Int32 option values. /// String options are in the following format: /// /stringOption value /// Int32 options are in the following format: /// /intOption 200 /// Boolean options are in the following format: /// /boolOption /// NOTE: if the Boolean option is present in the command line, it is true. /// /// Supports both a long and short version for each option (e.g. /a and /Account /// can be mapped to the same value). /// NOTE: When