Table of Contents

Class ValueParser

Namespace
McMaster.Extensions.CommandLineUtils.Abstractions
Assembly
McMaster.Extensions.CommandLineUtils.dll

Provides methods for creating IValueParser<T> boilerplate implementations.

public static class ValueParser
Inheritance
object
ValueParser

Methods

Create(Type, Func<string?, string?, CultureInfo, object>)

Creates an IValueParser implementation for a type given a parsing function that receives an argument name, a value to parse and a culture to use for parsing.

public static IValueParser Create(Type targetType, Func<string?, string?, CultureInfo, object> parser)

Parameters

targetType Type
parser Func<string, string, CultureInfo, object>

Returns

IValueParser

Create<T>(Func<string, CultureInfo, (bool, T)>)

Creates an IValueParser<T> implementation given a parsing function that receives an argument name, a value to parse, a culture to use for parsing and returns a tuple whose first element indicates whether parsing was successful and second element is the parsed value.

public static IValueParser<T> Create<T>(Func<string, CultureInfo, (bool, T)> parser)

Parameters

parser Func<string, CultureInfo, (bool, T)>

Returns

IValueParser<T>

Type Parameters

T

Create<T>(Func<string, CultureInfo, (bool, T)>, Func<string?, string?, FormatException>)

Creates an IValueParser<T> implementation given a parsing function that receives an argument name, a value to parse, a culture to use for parsing and returns a tuple whose first element indicates whether parsing was successful and second element is the parsed value. An additional parameter specifies a function that returns the FormatException to throw, given the argument name and value, when parsing is unsuccessful.

public static IValueParser<T> Create<T>(Func<string, CultureInfo, (bool, T)> parser, Func<string?, string?, FormatException> errorSelector)

Parameters

parser Func<string, CultureInfo, (bool, T)>
errorSelector Func<string, string, FormatException>

Returns

IValueParser<T>

Type Parameters

T

Create<T>(Func<string?, string?, CultureInfo, T>)

Creates an IValueParser<T> implementation given a parsing function that receives an argument name, a value to parse and a culture to use for parsing.

public static IValueParser<T> Create<T>(Func<string?, string?, CultureInfo, T> parser)

Parameters

parser Func<string, string, CultureInfo, T>

Returns

IValueParser<T>

Type Parameters

T