Creating Commands
From ReflexCLI
Creating Commands:
You can create commands from any c# methods, fields or properties by adding the [ConsoleCommand]
attribute.
Basic Example
using ReflexCLI.Attributes; namespace CommandTest { class TestCommandLibrary { [ConsoleCommand] private static string Echo(string in) { return in; } [ConsoleCommand] protected static int IntegerField = 32; [ConsoleCommand] public static bool BooleanProperty { get { return IntegerField > 0; } } } }
This will create the following commands:
CommandTest.TestCommandLibrary.Echo
CommandTest.TestCommandLibrary.IntegerField
CommandTest.TestCommandLibrary.BooleanProperty
Customising Command Names
By default, the commands are given fully-qualified names with namespaces etc., which can get pretty verbose. This can be fixed by using a [CommandConsoleClassCustomizer] attribute on the class:
namespace CommandTest { [ConsoleCommandClassCustomizer("TestCommands")] class TestCommandLibrary { // etc.
This will change the prefix of the commands to TestCommand
. and so the commands become:
-
TestCommands.Echo
-
TestCommands.IntegerField
-
TestCommands.BooleanProperty
You can also customize the name of the commands by adding the optional parameter to [ConsoleCommand]
. For example
[ConsoleCommand("Int")] protected static int IntegerField = 32;
which will change this command to be TestCommands.Int
.