Skip to content

Loading commands from external types

mtmk edited this page Jun 2, 2011 · 5 revisions

In other examples, we have used CommandRunner in a similar way to the following:

    new CommandRunner().Run(args);

To load a single command from a specific type, the following code can be used:

    new CommandRunner().WithCommandFromType(typeof(MyCommand));

This will add the command "MyCommand" regardless of whether the "[Command]" attribute has been applied.

To load all the commands from a specific assembly, the following can be used:

    new CommandRunner().WithCommandsFromAssembly(myAssembly);

For example:

    new CommandRunner().WithCommandsFromAssembly(Assembly.GetAssembly(typeof(MyCommand)));

These methods can be chained as necessary to combine types from external assemblies with specific types.

Note: By default, if no commands have been specified manually, Assembly.GetCallingAssembly() is used to load the command list. It is also important to remember that the automatic loading of commands is disabled when using any of these methods.