Table of Contents

Class CommandDescriptor

Namespace
Signal.Application.Commands
Assembly
Signal.Application.dll

Everything the framework knows about a command: metadata, parameters, preconditions and how to invoke it. Created by the registry from ICommand classes and CommandModule methods, or directly for delegate commands.

public sealed class CommandDescriptor
Inheritance
CommandDescriptor
Inherited Members

Constructors

CommandDescriptor(string, Func<CommandContext, object?[], Task>, Type, IEnumerable<string>?, string?, string?, IEnumerable<CommandParameter>?, IEnumerable<PreconditionAttribute>?, bool, MethodInfo?)

Creates a descriptor.

public CommandDescriptor(string name, Func<CommandContext, object?[], Task> executor, Type declaringType, IEnumerable<string>? aliases = null, string? description = null, string? usage = null, IEnumerable<CommandParameter>? parameters = null, IEnumerable<PreconditionAttribute>? preconditions = null, bool hidden = false, MethodInfo? method = null)

Parameters

name string

The command name (no whitespace).

executor Func<CommandContext, object[], Task>

Invokes the command with the bound values (in parameters order).

declaringType Type

The type that defines the command (used in diagnostics).

aliases IEnumerable<string>

Alternative names.

description string

One-line description for help.

usage string

Custom usage text without prefix.

parameters IEnumerable<CommandParameter>

Bindable parameters.

preconditions IEnumerable<PreconditionAttribute>

Checks to run before execution; sorted by Order.

hidden bool

Hide from the help listing.

method MethodInfo

The command method for module commands.

Exceptions

ArgumentException

name is empty or contains whitespace.

Properties

Aliases

Alternative names.

public IReadOnlyList<string> Aliases { get; }

Property Value

IReadOnlyList<string>

Category

The help heading from CategoryAttribute, if any.

public string? Category { get; init; }

Property Value

string

DeclaringType

The type that defines the command.

public Type DeclaringType { get; }

Property Value

Type

Description

One-line description for help.

public string? Description { get; }

Property Value

string

Examples

Example invocations without prefix, from ExampleAttribute.

public IReadOnlyList<string> Examples { get; init; }

Property Value

IReadOnlyList<string>

Executor

Invokes the command with the bound parameter values (in Parameters order).

public Func<CommandContext, object?[], Task> Executor { get; }

Property Value

Func<CommandContext, object[], Task>

FullName

The name as typed after the prefix: group name for grouped commands, otherwise Name.

public string FullName { get; }

Property Value

string

Group

The group the command belongs to, or null for a top-level command.

public CommandGroupInfo? Group { get; init; }

Property Value

CommandGroupInfo

Hidden

Whether the command is hidden from the help listing.

public bool Hidden { get; }

Property Value

bool

Method

The command method for module commands; null otherwise.

public MethodInfo? Method { get; }

Property Value

MethodInfo

Name

The command name (within its Group, if any).

public string Name { get; }

Property Value

string

Parameters

Bindable parameters in declaration order.

public IReadOnlyList<CommandParameter> Parameters { get; }

Property Value

IReadOnlyList<CommandParameter>

Preconditions

Preconditions in execution order.

public IReadOnlyList<PreconditionAttribute> Preconditions { get; }

Property Value

IReadOnlyList<PreconditionAttribute>

Usage

Custom usage text without prefix, or null to generate it.

public string? Usage { get; }

Property Value

string

Methods

FormatUsage(string)

Formats the usage line, e.g. /add <a> <b> or /playlist add <song...>.

public string FormatUsage(string prefix)

Parameters

prefix string

The prefix to show (usually the one the user typed).

Returns

string

The usage line.

ToString()

Returns FullName.

public override string ToString()

Returns

string

The command name, including the group.