Click or drag to resize

SimpleParse Class

A very simple parser for an argument array that follows a popular modern convention where positional arguments preceed the first switch in the format /name. Each switch can have zero or more values that follow it in the format /name value1 value2 ... until the next switch or end of arguments is reached. Multiple switches of the same name have their values merged. The arguments are not validated during parsing, they are just placed into arrays of the two argument types (Positional and Switch) and convenient methods are provided to query them.
Inheritance Hierarchy
SystemObject
  Orthogonal.Common.BasicSimpleParse

Namespace: Orthogonal.Common.Basic
Assembly: Orthogonal.Common.Basic (in Orthogonal.Common.Basic.dll) Version: 2024-04-15 18:00 GMT+10.f27da1471008deaf16b803c17e24a5955690aef1
Syntax
C#
public class SimpleParse

The SimpleParse type exposes the following members.

Constructors
 NameDescription
Public methodSimpleParseInitializes a new instance of the SimpleParse class
Top
Properties
 NameDescription
Public propertyIsEmpty Gets a flag indicating if no arguments of any type are specifeid.
Public propertyIsHelp Gets a flag indicating if the only argument is the single switch /?.
Public propertyPositionalCount Gets a count of positional arguments.
Public propertyPositionals Gets an array of positional argument strings.
Public propertySwitchCount Gets a count of distinct switch arguments.
Public propertySwitches Gets an array of Switch class instances, each containing full information about each distinct switch argument.
Top
Methods
 NameDescription
Public methodGetPositional Gets a positional argument at a specified index. Null is returned if there is no positional argument at the index.
Public methodGetPositionalInt Gets a positional argument at a specified index converted to an Int32. Null is returned if there is no positional argument at the index or the value cannot be converted to an Int32.
Public methodGetSwitch Gets the first value of a switch argument in the format /name value. Null is returned if the switch is not specified or it has no values.
Public methodGetSwitchData Gets a reference to a Switch class instance containing full information about a switch. Null is returned if the switch is not found. This is the only way to get the Parity of a switch.
Public methodGetSwitchDouble Gets the first value of a switch argument in the format /name value converted to a Double. Null is returned if the switch is not specified or it has no values or the first value cannot be converted to a Double.
Public methodGetSwitchInt Gets the first value of a switch argument in the format /name value converted to an Int32. Null is returned if the switch is not specified or it has no values or the first value cannot be converted to an Int32.
Public methodGetSwitchValue Gets a switch argument value in the format /name value1 value2 at a specified index. Null is returned if the switch is not specified or there is no value at the specified index.
Public methodGetSwitchValueInt Gets a switch argument value in the format /name value1 value2 at a specified index converted to an Int32. Null is returned if the switch is not specified or there is no value at the specified index or it cannot be converted to an Int32.
Public methodGetSwitchValues Gets all switch argument values as a string array. The return value will be null if the switch is not specified. The returned array may be zero-length if there are no values.
Public methodHasSwitch Gets a flag indicating if a simple switch argument in the format /name is specified or not.
Public methodStatic memberParse A static factory method that performs simple parsing of an argument array and returns an instance of the SimpleParse class containing the parsing results.
Top
See Also