C# Class FastFind.ArgParser

A command line argument parsing class.
This class is based on the WordCount version from the Framework SDK samples. Any errors are mine.

There are two arrays of flags you'll pass to the constructors. The flagSymbols are supposed to be standalone switches that toggle an option on. The dataSymbols are for switches that take data values. For example, if your application needs a switch, -c, to set the count, you'd put "c" in the dataSymbols. This code will allow both "-c100" and the usual "-c" "100" both to be passed on the command line. Note that you can pass null/Nothing for dataSymbols if you don't need them.

Datei anzeigen Open project: Wintellect/FastFileFinder

Public Methods

Method Description
OnUsage ( String errorInfo ) : void

Reports correct command line usage.

Parse ( String args ) : System.Boolean

Parses an arbitrary set of arguments.

Protected Methods

Method Description
OnDoneParse ( ) : SwitchStatus

Called when parsing is finished so final sanity checking can be performed.

OnNonSwitch ( String value ) : SwitchStatus

Called when a non-switch value is parsed out.

OnSwitch ( String switchSymbol, String switchValue ) : SwitchStatus

Called when a switch is parsed out.

Every derived class must implement an OnSwitch method or a switch is considered an error.

Private Methods

Method Description
ArgParser ( String flagSymbols, String dataSymbols, System.Boolean caseSensitiveSwitches ) : System
ArgParser ( String flagSymbols, String dataSymbols, System.Boolean caseSensitiveSwitches, String switchChars ) : System
IsSwitchInArray ( String switchArray, String value ) : Int32

Looks to see if the switch is in the array.

StartsWithSwitchChar ( String value ) : System.Boolean

Looks to see if this string starts with a switch character.

Method Details

OnDoneParse() protected method

Called when parsing is finished so final sanity checking can be performed.
protected OnDoneParse ( ) : SwitchStatus
return SwitchStatus

OnNonSwitch() protected method

Called when a non-switch value is parsed out.
protected OnNonSwitch ( String value ) : SwitchStatus
value String /// The value parsed out. ///
return SwitchStatus

OnSwitch() protected method

Called when a switch is parsed out.
Every derived class must implement an OnSwitch method or a switch is considered an error.
protected OnSwitch ( String switchSymbol, String switchValue ) : SwitchStatus
switchSymbol String /// The switch value parsed out. ///
switchValue String /// The value of the switch. For flag switches this is null/Nothing. ///
return SwitchStatus

OnUsage() public abstract method

Reports correct command line usage.
public abstract OnUsage ( String errorInfo ) : void
errorInfo String /// The string with the invalid command line option. ///
return void

Parse() public method

Parses an arbitrary set of arguments.
/// Thrown if is null. ///
public Parse ( String args ) : System.Boolean
args String /// The string array to parse through. ///
return System.Boolean