Table of Contents

Class ArgumentsHandler

Namespace
Webefinity.Switch
Assembly
Switch.dll

Validates the arguments according to the list of options.

public class ArgumentsHandler
Inheritance
ArgumentsHandler
Inherited Members

Constructors

ArgumentsHandler(string[], IReadOnlyCollection<ArgumentOption>)

Validate arguments.

Constructing the ArgumentsHandler immediately validates the passed options against the passed argument list.

public ArgumentsHandler(string[] args, IReadOnlyCollection<ArgumentOption> options)

Parameters

args string[]

The arguments to use.

options IReadOnlyCollection<ArgumentOption>

The options to validate the arguments against

Exceptions

ValueProviderException

Thrown if any option is missing a value provider.

Properties

Errors

What were the errors recorded, in the case of invalidity. A value provider need not add errors, but it would be good practice for it to do so.

public ICollection<string> Errors { get; }

Property Value

ICollection<string>

IsValid

After parsing, were the arguments valid?

public bool IsValid { get; }

Property Value

bool

Methods

GetValue<T>(string)

Get the value of an option as a strongly typed value, by long option name.

public T? GetValue<T>(string longOption)

Parameters

longOption string

The long version of the option flag, without the leading --.

Returns

T

The value.

Type Parameters

T

The type you expect.

Usage(string, string, bool, Action<string>?)

Report the usage using a logger, or default to Console.Write as the logger.

public void Usage(string name, string version, bool showErrors = true, Action<string>? log = null)

Parameters

name string

The name of the application.

version string

The version of the application.

showErrors bool

Should errors be logged, or suppressed?

log Action<string>

The logger, or null to use Console.Writeline