Skip to main content

Command

A class in Root.Township, Alta.Console.

One console command built from a method with a CommandAttribute. Matches typed words against its name and parameters and calls the method. The method is called with no instance, so it must be static.

Constructors​

MemberWhat it is
Command(MethodInfo method, Module parent, CommandAttribute attribute)Creates a Command from method, parent and attribute.

Fields​

3 private and internal fields
MemberWhat it is
private static Logger loggerNLog logger for this class.
private MethodInfo methodThe static method the command calls.
private static readonly Type VoidTaskResultThe runtime's internal VoidTaskResult type, used to tell a plain Task from one with a result.

Properties​

MemberWhat it is
CommandAttribute Attribute { get; set; }The CommandAttribute the command was made from.
Func<ProgressiveHandler, object[], Task<CommandResult>> InvokeCommand { get; private set; }Calls the method with converted arguments and wraps what it returns (awaiting tasks) in a CommandResult.
bool IsLoggingValueAsTable { get; set; }Whether the result is logged as a table.
bool IsProgressive { get; set; }Progressive commands are not supported; invoking one returns an error result.
MethodInfo Method { get; }Meant to be the method behind the command, but never set in this build, so it is null.
List<Parameter> Parameters { get; }The command's parameters. A last string or array parameter takes all remaining words.
Type ReturnType { get; }What the method returns, with Task unwrapped; void for none.

Methods​

MemberWhat it is
override string ToString()Full command path followed by its parameters.
protected override IEnumerable<CommandPart> GetCommandPartInternal(string[] lower, string[] cased, int index, CommandContext context) (iterator)Returns this command if the words end at its name.
protected override IEnumerable<CommandSearchResult> GetCommandsInternal(string[] lower, string[] cased, int index, CommandContext context) (iterator)Tries to match the words after the command name to its parameters and returns the result.
3 private and internal methods
MemberWhat it is
private CommandSearchResult AreParametersViable(string[] lower, string[] cased, int index)Checks the argument count against the parameters and converts them. A last string or array parameter takes the rest.
private bool AttemptConvertArguments(int matchedCount, string[] argumentParts, int index, object[] convertedArguments)Converts each argument with its parameter type's converter. Fails on a null result unless AllowNull is set.
private async Task<CommandResult> Invoke(ProgressiveHandler progressivehandler, object[] args)Calls the command method with no instance (so it must be static) and wraps what it returns in a CommandResult. Progressive commands return an error.

Used in​

Members of other types that take, return or hold a Command: