ArgumentBinderAliases.

CreateFromArguments<T>(ICakeContext, object[]) Method

Summary

Creates an instance of a class that can bind arguments to.

Syntax

public static T CreateFromArguments<T>(this ICakeContext context, params object[] constructorArgs)

Examples

Create a MyConfig object based on the passed in command line arguments.

public class MyConfig
    {
        [BooleanArgument(
            "dry_run",
            Description = "Set to 'true' to not do anything.",
            DefaultValue = false
        )]
        public bool DryRun { get; set; }
    }
    
    MyConfig config = CreateFromArguments<MyConfig>();
    
    // If --dry_run=true is was passed into the command line, config.DryRun will be set to true,
    // otherwise it will be set to false.

Attributes

Type Description
CakeMethodAliasAttribute
CakeAliasCategoryAttribute
CakeNamespaceImportAttribute

Type Parameters

Name Description
T The type of class to bind arguments to.

Parameters

Name Type Description
context ICakeContext
constructorArgs object[] Any constructor arguments for the config class, if any.

Return Value

Type Description
T A new object of type T that has attributes binded to.