Class CommandAttributeUtility
Utility methods for accessing command attribute information on the types in an assembly.
Inherited Members
Namespace: Benday.CommandsFramework
Assembly: Benday.CommandsFramework.dll
Syntax
public class CommandAttributeUtility
Constructors
| Edit this page View SourceCommandAttributeUtility(ICommandProgramOptions)
Declaration
public CommandAttributeUtility(ICommandProgramOptions options)
Parameters
| Type | Name | Description |
|---|---|---|
| ICommandProgramOptions | options |
Methods
| Edit this page View SourceGetAllCommandUsages(Assembly)
Creates a list of command usages for all the commands in an assembly
Declaration
public List<CommandInfo> GetAllCommandUsages(Assembly asm)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | asm | Assembly to check |
Returns
| Type | Description |
|---|---|
| List<CommandInfo> | List of command usages |
GetAvailableCommandAttributes(Assembly)
Get all the command attributes for all the command types in an assembly.
Declaration
public List<CommandAttribute> GetAvailableCommandAttributes(Assembly containingAssembly)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly to check |
Returns
| Type | Description |
|---|---|
| List<CommandAttribute> | List of command attributes from this assembly. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetAvailableCommandNames(Assembly)
Get the list of command names in an assembly
Declaration
public List<string> GetAvailableCommandNames(Assembly containingAssembly)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly to examine |
Returns
| Type | Description |
|---|---|
| List<string> | List of command names for all classes with a CommandAttribute in the assembly |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetAvailableCommandType(Assembly, string)
Gets command type from an assembly by command name.
Declaration
public Type? GetAvailableCommandType(Assembly containingAssembly, string commandName)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
| string | commandName | Command name to find. This is typically args[0] from the command line. |
Returns
| Type | Description |
|---|---|
| Type | Instance of System.Type for the matching command or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetCommand(string[], Assembly)
Gets a populated instance of a command using arguments from the command line. This uses args[0] as the command name. The rest of the arguments are used as argument values to the command.
Declaration
public CommandBase? GetCommand(string[] args, Assembly containingAssembly)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | args | Command line arguments |
| Assembly | containingAssembly | Assembly that contains the commands |
Returns
| Type | Description |
|---|---|
| CommandBase | Populated command |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| ArgumentException | |
| MissingArgumentException |
GetCommandAlias(Assembly, string)
Gets the alias that matches a name, if there is one. Use this to find the argument values that an alias supplies.
Declaration
public CommandAliasInfo? GetCommandAlias(Assembly containingAssembly, string alias)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
| string | alias | Alias to look for |
Returns
| Type | Description |
|---|---|
| CommandAliasInfo | The matching alias or null when nothing matches |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetCommandAliases(Assembly)
Gets every alternate name for the commands in an assembly. This covers the plain aliases declared by CommandAttribute.Aliases as well as the aliases declared by CommandAliasAttribute, which also supply argument values.
Declaration
public List<CommandAliasInfo> GetCommandAliases(Assembly containingAssembly)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
Returns
| Type | Description |
|---|---|
| List<CommandAliasInfo> | List of aliases |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetCommandAttributeForCommandName(Assembly, string)
Get a command argument for a command by command name.
Declaration
public CommandAttribute? GetCommandAttributeForCommandName(Assembly containingAssembly, string commandName)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
| string | commandName | Command name to find. This is typically args[0] from the command line. |
Returns
| Type | Description |
|---|---|
| CommandAttribute | Command argument for the command or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetCommandNameProblems(List<CommandAttribute>, List<CommandAliasInfo>?)
Checks a set of commands for command name and alias problems. Nothing in the framework calls this automatically -- it is intended to be called from a unit test so that alias problems are caught at build time rather than showing up as a command that mysteriously cannot be run.
Declaration
public List<string> GetCommandNameProblems(List<CommandAttribute> attributes, List<CommandAliasInfo>? aliases = null)
Parameters
| Type | Name | Description |
|---|---|---|
| List<CommandAttribute> | attributes | Command attributes to check |
| List<CommandAliasInfo> | aliases | Aliases to check. When null, the aliases declared by CommandAttribute.Aliases are used. |
Returns
| Type | Description |
|---|---|
| List<string> | Human readable descriptions of any problems found. Empty when everything is fine. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
GetCommandNameProblems(Assembly)
Checks the commands in an assembly for command name and alias problems. Nothing in the framework calls this automatically -- it is intended to be called from a unit test so that alias problems are caught at build time rather than showing up as a command that mysteriously cannot be run.
Declaration
public List<string> GetCommandNameProblems(Assembly containingAssembly)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
Returns
| Type | Description |
|---|---|
| List<string> | Human readable descriptions of any problems found. Empty when everything is fine. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
ResolveCommandName(List<CommandAttribute>, string)
Resolves a command name or command alias to the real command name. Real command names always take precedence over aliases, so an alias can never shadow an actual command.
Declaration
public string? ResolveCommandName(List<CommandAttribute> attributes, string nameOrAlias)
Parameters
| Type | Name | Description |
|---|---|---|
| List<CommandAttribute> | attributes | Command attributes to search |
| string | nameOrAlias | Command name or alias. This is typically args[0] from the command line. |
Returns
| Type | Description |
|---|---|
| string | The real command name, or null when nothing matches |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| KnownException | Thrown when the alias is claimed by more than one command |
ResolveCommandName(Assembly, string)
Resolves a command name or command alias to the real command name. Real command names always take precedence over aliases, so an alias can never shadow an actual command.
Declaration
public string? ResolveCommandName(Assembly containingAssembly, string nameOrAlias)
Parameters
| Type | Name | Description |
|---|---|---|
| Assembly | containingAssembly | Assembly containing the commands |
| string | nameOrAlias | Command name or alias. This is typically args[0] from the command line. |
Returns
| Type | Description |
|---|---|
| string | The real command name, or null when nothing matches |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | |
| KnownException | Thrown when the alias is claimed by more than one command |