Show / Hide Table of Contents

Class CommandAttributeUtility

Utility methods for accessing command attribute information on the types in an assembly.

Inheritance
object
CommandAttributeUtility
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.CommandsFramework
Assembly: Benday.CommandsFramework.dll
Syntax
public class CommandAttributeUtility

Constructors

| Edit this page View Source

CommandAttributeUtility(ICommandProgramOptions)

Declaration
public CommandAttributeUtility(ICommandProgramOptions options)
Parameters
Type Name Description
ICommandProgramOptions options

Methods

| Edit this page View Source

GetAllCommandUsages(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

| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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
| Edit this page View Source

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

| Edit this page View Source

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

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com