Table of Contents

CliBindingContext.Bind Method

Definition

Namespace
DotMake.CommandLine
Assembly
DotMake.CommandLine.dll

Bind<TDefinition>(ParseResult, bool)

Creates a new instance of the command definition class and binds/populates the properties from the parse result.

Note that binding will be done only once per parse result and definition class, so calling this method consecutively for the same parse result and the same definition class will return the cached result.

If the command line input does not contain the indicated definition class (as self or as a parent), this method will return null unless returnEmpty is set to true, in that case it will return an empty instance with default property values.

public TDefinition Bind<TDefinition>(ParseResult parseResult, bool returnEmpty = false)

Parameters

parseResult ParseResult

A parse result describing the outcome of the parse operation.

returnEmpty bool

Whether to return an empty instance with default property values instead of null if the command line input does not contain the indicated definition class (as self or as a parent).

Returns

TDefinition

An instance of the definition class whose properties were bound/populated from the parse result.

Type Parameters

TDefinition

The definition class for the command. A command builder for this class should be automatically generated by the source generator.

Bind(ParseResult, Type, bool)

Creates a new instance of the command definition class and binds/populates the properties from the parse result.

Note that binding will be done only once per parse result and definition class, so calling this method consecutively for the same parse result and the same definition class will return the cached result.

If the command line input does not contain the indicated definition class (as self or as a parent), this method will return null unless returnEmpty is set to true, in that case it will return an empty instance with default property values.

public object Bind(ParseResult parseResult, Type definitionType, bool returnEmpty = false)

Parameters

parseResult ParseResult

A parse result describing the outcome of the parse operation.

definitionType Type

The definition class type for the command. A command builder for this class should be automatically generated by the source generator.

returnEmpty bool

Whether to return an empty instance with default property values instead of null if the command line input does not contain the indicated definition class (as self or as a parent).

Returns

object

An instance of the definition class whose properties were bound/populated from the parse result.