-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommandContext.cs
More file actions
72 lines (63 loc) · 2.45 KB
/
CommandContext.cs
File metadata and controls
72 lines (63 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using Ultz.Extensions.Commands.Built;
namespace Ultz.Extensions.Commands.Context
{
/// <summary>
/// The base class for custom command contexts.
/// </summary>
/// <remarks>
/// The properties this class exposes may not always be present, depending on how the <see cref="Built.Command" /> was
/// executed.
/// </remarks>
public abstract class CommandContext
{
private List<object> _arguments;
internal object[] InternalArguments;
/// <summary>
/// Initialises a new instance of the <see cref="CommandContext" />.
/// </summary>
/// <param name="serviceProvider">
/// The <see cref="IServiceProvider" /> to use for execution. Passing <see langword="null" /> will make it default to a
/// <see cref="DummyServiceProvider" />.
/// </param>
protected CommandContext(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider ?? DummyServiceProvider.Instance;
}
/// <summary>
/// Gets the currently executed <see cref="Built.Command" />.
/// </summary>
public Command Command { get; internal set; }
/// <summary>
/// Gets the alias used.
/// <see langword="null" /> if the <see cref="Built.Command" /> was invoked without searching.
/// </summary>
public string Alias { get; internal set; }
/// <summary>
/// Gets the alias path used.
/// <see langword="null" /> if the <see cref="Built.Command" /> was invoked without searching.
/// </summary>
public IReadOnlyList<string> Path { get; internal set; }
/// <summary>
/// Gets the raw arguments.
/// <see langword="null" /> if the <see cref="Built.Command" /> was invoked with already parsed arguments.
/// </summary>
public string RawArguments { get; internal set; }
/// <summary>
/// Gets the parsed arguments.
/// </summary>
public IReadOnlyList<object> Arguments
{
get
{
var arguments = _arguments;
return arguments ?? (_arguments = new List<object>(InternalArguments ?? Array.Empty<object>()));
}
}
/// <summary>
/// Gets the <see cref="IServiceProvider" /> used for execution.
/// </summary>
public IServiceProvider ServiceProvider { get; }
}
}