Class ConventionBuilderExtensions
Methods for adding commonly used conventions
Inheritance
Namespace: McMaster.Extensions.CommandLineUtils
Assembly: McMaster.Extensions.CommandLineUtils.dll
Syntax
public static class ConventionBuilderExtensions
Methods
| Improve this Doc View SourceSetAppNameFromEntryAssembly(IConventionBuilder)
Sets Name to match the name of System.Reflection.Assembly.GetEntryAssembly
Declaration
public static IConventionBuilder SetAppNameFromEntryAssembly(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
SetParentPropertyOnModel(IConventionBuilder)
Sets a property named "Parent" on the model type to the value of the model of the parent command.
Declaration
public static IConventionBuilder SetParentPropertyOnModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
SetRemainingArgsPropertyOnModel(IConventionBuilder)
Sets a property named "RemainingArgs" or "RemainingArguments" on the model type to the value of RemainingArguments.
Declaration
public static IConventionBuilder SetRemainingArgsPropertyOnModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
SetSubcommandPropertyOnModel(IConventionBuilder)
Sets a property named "Subcommand" on the model type to the value of the model of the selected subcommand.
Declaration
public static IConventionBuilder SetSubcommandPropertyOnModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseArgumentAttributes(IConventionBuilder)
Applies settings from ArgumentAttribute on the model type.
Declaration
public static IConventionBuilder UseArgumentAttributes(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseAttributes(IConventionBuilder)
Applies a collection of default conventions, such as applying options in attributes on the model type,
Declaration
public static IConventionBuilder UseAttributes(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseCommandAttribute(IConventionBuilder)
Applies settings from CommandAttribute on the model type.
Declaration
public static IConventionBuilder UseCommandAttribute(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseCommandNameFromModelType(IConventionBuilder)
Sets the subcommand name using the model type, if available and not otherwise set using CommandAttribute.
Declaration
public static IConventionBuilder UseCommandNameFromModelType(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder |
Returns
Type | Description |
---|---|
IConventionBuilder |
UseConstructorInjection(IConventionBuilder)
Enables using constructor injection to initialize the model type.
Declaration
public static IConventionBuilder UseConstructorInjection(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder |
Returns
Type | Description |
---|---|
IConventionBuilder |
UseConstructorInjection(IConventionBuilder, IServiceProvider)
Enables using constructor injection to initialize the model type.
Declaration
public static IConventionBuilder UseConstructorInjection(this IConventionBuilder builder, IServiceProvider additionalServices)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | |
System.IServiceProvider | additionalServices | Additional services that should be passed to the service provider. |
Returns
Type | Description |
---|---|
IConventionBuilder |
UseDefaultConventions(IConventionBuilder)
Applies a collection of default conventions, such as applying options in attributes on the model type,
Declaration
public static IConventionBuilder UseDefaultConventions(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseDefaultHelpOption(IConventionBuilder, String)
Adds --help option, if there isn't already a help flag set.
Declaration
public static IConventionBuilder UseDefaultHelpOption(this IConventionBuilder builder, string template = "-?|-h|--help")
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
System.String | template | The help template. Defaults to |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseHelpOptionAttribute(IConventionBuilder)
Applies settings from HelpOptionAttribute on the model type.
Declaration
public static IConventionBuilder UseHelpOptionAttribute(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseOnExecuteMethodFromModel(IConventionBuilder)
Sets a method named "OnExecute" or "OnExecuteAsync" on the model type to handle OnExecute(Func<Int32>)
Declaration
public static IConventionBuilder UseOnExecuteMethodFromModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseOnValidateMethodFromModel(IConventionBuilder)
Invokes a method named "OnValidate" on the model type after parsing.
Declaration
public static IConventionBuilder UseOnValidateMethodFromModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseOnValidationErrorMethodFromModel(IConventionBuilder)
Invokes a method named "OnValidationError" on the model type when validation fails.
Declaration
public static IConventionBuilder UseOnValidationErrorMethodFromModel(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseOptionAttributes(IConventionBuilder)
Applies settings from OptionAttribute on the model type.
Declaration
public static IConventionBuilder UseOptionAttributes(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseSubcommandAttributes(IConventionBuilder)
Adds subcommands for each SubcommandAttribute on the model type.
Declaration
public static IConventionBuilder UseSubcommandAttributes(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseVersionOptionAttribute(IConventionBuilder)
Applies settings from VersionOptionAttribute on the model type.
Declaration
public static IConventionBuilder UseVersionOptionAttribute(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |
UseVersionOptionFromMemberAttribute(IConventionBuilder)
Applies settings from VersionOptionFromMemberAttribute on the model type.
Declaration
public static IConventionBuilder UseVersionOptionFromMemberAttribute(this IConventionBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
IConventionBuilder | builder | The builder. |
Returns
Type | Description |
---|---|
IConventionBuilder | The builder. |