Interface ICommandParameters
Represents the parameters of a command.
Namespace: OpenMod.API.Commands
Assembly: OpenMod.API.dll
Syntax
public interface ICommandParameters : IReadOnlyCollection<string>
Remarks
When a command was entered as "/mycommand test 5 b", this class will handle and represent "test", "5" and "b".
Properties
| Improve this Doc View SourceItem[Int32]
Gets the n. command parameter starting from zero.
Index must be less than Length and not negative.
Declaration
string this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the parameter. |
Property Value
Type | Description |
---|---|
System.String | The n. command parameter as string. |
See Also
Length
Gets the amount of parameters.
Declaration
int Length { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Examples
If the command was entered as "/mycommand test 5 b", it would return "3".
Methods
| Improve this Doc View SourceGetArgumentLine(Int32)
Returns the joined arguments starting from the given position.
Declaration
string GetArgumentLine(int startPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPosition | The zero based position to start from. |
Returns
Type | Description |
---|---|
System.String | he joined arguments starting from the given position |
Examples
If the command was entered as "/mycommand dosomething a bla c" it would return "a bla c" if startPosition was 1.
| Improve this Doc View SourceGetArgumentLine(Int32, Int32)
Returns the joined arguments starting at the given position.
Declaration
string GetArgumentLine(int startPosition, int endPosition)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startPosition | The zero based position to start from. |
System.Int32 | endPosition | The end position. |
Returns
Type | Description |
---|---|
System.String | he joined arguments starting from the given position |
Examples
If the command was entered as "/mycommand dosomething a bla c" it would return "a bla" if startPosition was 1 and endPosition was 2.
| Improve this Doc View SourceGetAsync(Int32, Type)
Declaration
Task<object> GetAsync(int index, Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
Type | type | The type to parse the parameter as. |
Returns
Type | Description |
---|---|
Task<System.Object> |
GetAsync(Int32, Type, Nullable<Object>)
Declaration
Task<object?> GetAsync(int index, Type type, object? defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
Type | type | The type to parse the parameters as. |
System.Nullable<System.Object> | defaultValue | The default return value. |
Returns
Type | Description |
---|---|
Task<System.Nullable<System.Object>> |
GetAsync<T>(Int32)
Gets the parameter value at the given index. The value will parsed to the given type.
Types like IPlayer, IOnlinePlayer, etc. are supported.
Declaration
Task<T> GetAsync<T>(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based parameter index. |
Returns
Type | Description |
---|---|
Task<T> | The parsed parameter value. |
Type Parameters
Name | Description |
---|---|
T | The type to parse the parameter as. |
Examples
Assume the command was entered as "/mycommand test 5 b".
Get<string>(0)
would be equal to "test" (string).
Get<int>(1)
would be equal to 5 (int).
Get<string>(1)
would be equal to "5" (string).
Get<string>(2)
would be equal to "b" (string).
GetAsync<T>(Int32, T)
Declaration
Task<T> GetAsync<T>(int index, T defaultValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
T | defaultValue | The default return value. |
Returns
Type | Description |
---|---|
Task<T> | the parsed parameter value if the given index was valid and the parameter could be parsed to the given type; otherwise defaultValue. |
Type Parameters
Name | Description |
---|---|
T |
ToArray()
Gets the parameters as string array.
Declaration
string[] ToArray()
Returns
Type | Description |
---|---|
System.String[] | the parameters as string array. |
ToList()
Gets the parameters as string list.
Declaration
List<string> ToList()
Returns
Type | Description |
---|---|
List<System.String> | the parameters as string list. |
TryGet(Int32, Type, out Nullable<Object>)
Declaration
bool TryGet(int index, Type type, out object? value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
Type | type | The type to parse the parameters as. |
System.Nullable<System.Object> | value | The parsed parameter value. |
Returns
Type | Description |
---|---|
System.Boolean |
TryGet<T>(Int32, out T)
Tries to get and parse a parameter. See GetAsync<T>(Int32).
Declaration
bool TryGet<T>(int index, out T value)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
T | value | The parsed parameter value. |
Returns
Type | Description |
---|---|
System.Boolean | true if the given index was valid and the parameter could be parsed to the given type; otherwise false. |
Type Parameters
Name | Description |
---|---|
T |