Class CommandService<TContext>
Provides functionality for handling text-based commands.
public class CommandService<TContext> : ICommandService, IService where TContext : ICommandContext
Type Parameters
TContextThe context the invoked commands use.
- Inheritance
-
CommandService<TContext>
- Implements
- Inherited Members
Constructors
CommandService(CommandServiceConfiguration<TContext>?)
Provides functionality for handling text-based commands.
public CommandService(CommandServiceConfiguration<TContext>? configuration = null)
Parameters
configurationCommandServiceConfiguration<TContext>The configuration for the command service.
Properties
Configuration
The configuration for the command service.
public CommandServiceConfiguration<TContext> Configuration { get; }
Property Value
- CommandServiceConfiguration<TContext>
Methods
AddCommand(CommandBuilder)
Adds a command to the service.
public void AddCommand(CommandBuilder builder)
Parameters
builderCommandBuilderThe command builder.
AddCommandGroup(CommandGroupBuilder)
Adds a command group to the service.
public void AddCommandGroup(CommandGroupBuilder builder)
Parameters
builderCommandGroupBuilderThe command group builder.
AddModule(Type)
Adds a command module to the service.
public void AddModule(Type type)
Parameters
typeTypeThe type of the command module to add.
AddModule<T>()
Adds a command module to the service.
public void AddModule<T>()
Type Parameters
TThe type of the command module to add.
AddModules(Assembly)
Scans the specified assembly for public modules and registers them with the service.
[RequiresUnreferencedCode("Types might be removed")]
public void AddModules(Assembly assembly)
Parameters
assemblyAssemblyThe assembly to scan for modules.
ExecuteAsync(int, TContext, IServiceProvider?)
Executes a command.
public ValueTask<IExecutionResult> ExecuteAsync(int prefixLength, TContext context, IServiceProvider? serviceProvider = null)
Parameters
prefixLengthintThe length of the prefix that was used to invoke the command.
contextTContextThe command context.
serviceProviderIServiceProviderThe service provider for dependency injection.
Returns
- ValueTask<IExecutionResult>
A task representing the execution result.
ExecuteAsync(ReadOnlyMemory<char>, TContext, IServiceProvider?)
Executes a command.
public ValueTask<IExecutionResult> ExecuteAsync(ReadOnlyMemory<char> command, TContext context, IServiceProvider? serviceProvider = null)
Parameters
commandReadOnlyMemory<char>The command text to execute, including the command name and parameters, excluding any prefix or suffix.
contextTContextThe command context.
serviceProviderIServiceProviderThe service provider for dependency injection.
Returns
- ValueTask<IExecutionResult>
A task representing the execution result.
GetCommands()
Gets the collection of commands registered in the service.
public IReadOnlyDictionary<ReadOnlyMemory<char>, IReadOnlyList<ICommandInfo<TContext>>> GetCommands()
Returns
- IReadOnlyDictionary<ReadOnlyMemory<char>, IReadOnlyList<ICommandInfo<TContext>>>
The collection of commands registered in the service.