Documentation for the C# command-line option parser

Project Home

The source for this library is hosted at SourceForge.

The project home page and this documentation can be accessed at http://csharpoptparse.sourceforge.net and the project summary page is located at http://sourceforge.net/projects/csharpoptparse.

Back to the top

Support and Licensing

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and 
limitations under the License.

Back to the top

If you find this code useful and you wish to support this project, please go here: Support This Project

Back to the top

Overview

Although there are a few command-line option parsers available for different languages including .NET, many were not flexible and robust. This library ports a large portion of the functionality from the Perl GetOpt library. In addition to this functionality, additional features have been added that integrate with the .NET language better.

The library revolves around the Parser class. This class uses an implementation of an IOptionResults interface to store results of parsing the command-line. The definition of the options can be done in two ways:

  1. Definition of a class to house options.
  2. Using instances of the OptionDefinition class.

Option class

The parser is able to reflect options from a class that uses attributes (The class does not need to implement or extend anything for this functionality). The attribute classes that can be used are:
Class Description
OptDefAttribute Define that a property or field can be given as an option
LongOptionNameAttribute Defines a long option for a field or property
ShortOptionNameAttribute Defines a short option name for a field or property
UseNameAsLongOptionAttribute Gives the ability to stop the name of a field or property being used to be used as an option name

OptionDefinition class

The OptionDefinition class provides a way to programmatically define options at run-time. There are several overloads to the constructor that accept either arguments to define the settings or using the string constructor that parses a Perl-like option definition. Using this method, the results are stored in a dictionary (see OptionResultsDictionary for a strongly-typed dictionary). The attributes are not used in this method.

Back to the top