Class ValueParserProvider
- Namespace
- McMaster.Extensions.CommandLineUtils.Abstractions
- Assembly
- McMaster.Extensions.CommandLineUtils.dll
A store of value parsers that are used to convert argument values from strings to types.
public class ValueParserProvider
- Inheritance
-
objectValueParserProvider
Properties
ParseCulture
Gets or sets the CultureInfo which is used to convert argument values to types.
public CultureInfo ParseCulture { get; set; }
Property Value
Remarks
The default value is CurrentCulture.
Methods
Add(IValueParser)
Add a new value parser to the provider.
public void Add(IValueParser parser)
Parameters
parserIValueParserAn instance of the parser that is used to convert an argument from a string.
Exceptions
- ArgumentException
A value parser with the same TargetType is already registered.
- ArgumentNullException
parseris null.
AddOrReplace(IValueParser)
Add a new value parser to the provider, or if a value provider already exists for
TargetType then replaces it with parser.
public void AddOrReplace(IValueParser parser)
Parameters
parserIValueParserAn instance of the parser that is used to convert an argument from a string.
Exceptions
- ArgumentNullException
parseris null.
AddRange(IEnumerable<IValueParser>)
Add collection of a new value parsers to the provider.
public void AddRange(IEnumerable<IValueParser> parsers)
Parameters
parsersIEnumerable<IValueParser>The collection whose parsers should be added.
Exceptions
- ArgumentException
A value parser with the same TargetType is already registered.
- ArgumentNullException
parsersis null.
GetParser(Type)
Returns a parser registered for the given type.
public IValueParser GetParser(Type type)
Parameters
typeType
Returns
GetParser<T>()
Returns a parser for the generic type T.
public IValueParser<T>? GetParser<T>()
Returns
- IValueParser<T>
Type Parameters
T
Remarks
If parser is not registered, null is returned.