Class CommandLineBinder
- Namespace
- Ubiquity.CommandLineParsing
- Assembly
- Ubiquity.CommandlineParsing.dll
Type specific command line argument binder.
public class CommandLineBinder
- Inheritance
-
CommandLineBinder
- Inherited Members
- Extension Methods
Remarks
Switches are matched against properties by an implementation of IOptionPropertyProvider to provide the properties. If no property name matches the command line switch, then a property with a CommandLineArgAttribute ShortName or LongName matching the switch is used. Duplicate switches are allowed if the property the option is bound to implements IList<T>.
Property values are set by using a TypeConverter associated with the property. Using converters allows for a class to support custom parsing of values (e.g. GUID values can be parsed directly to a GUID type). Custom types with a defined TypeConverter will support parsing to custom types.
Positional arguments are stored into an IList<T> of strings, which must be designated by the DefaultPropertyAttribute on the class of the instance the arguments are bound to. If no default property or an unsupported type exists for the property and positional arguments are provided an exception is thrown.
Constructors
CommandLineBinder()
Initializes a new instance of the CommandLineBinder class using ReflectionOptionPropertyProvideras the property provider.
public CommandLineBinder()
CommandLineBinder(IOptionPropertyProvider)
Initializes a new instance of the CommandLineBinder class for a given object instance.
public CommandLineBinder(IOptionPropertyProvider propertyProvider)
Parameters
propertyProvider
IOptionPropertyProviderProperty provider for resolving property names.
Methods
BindParseResults(object, IImmutableList<ICommandLineArgument>)
Binds a previously parsed list of arguments to an object instance.
public void BindParseResults(object instance, IImmutableList<ICommandLineArgument> parsedResults)
Parameters
instance
objectInstance of object to bind the arguments to.
parsedResults
IImmutableList<ICommandLineArgument>Results to bind to the object this binder is for.