Added parameter check to EngineCommand.cs

makes sure all invoke strings don't contain spaces. Scope change makes sure to not break parameter rules.
This commit is contained in:
Harrison Deng 2020-02-24 02:59:15 -05:00
parent 92f302875f
commit 029932910d

View File

@ -12,7 +12,7 @@ namespace RecrownedGTK.Tools.CommandProcessor
/// <summary>
/// the words a user can type that will invoke this command.
/// </summary>
protected string[] invokeStrings;
private string[] invokeStrings;
public string[] InvokeStrings { get { return invokeStrings; } }
/// <summary>
@ -24,6 +24,11 @@ namespace RecrownedGTK.Tools.CommandProcessor
public EngineCommand(params string[] invokeStrings)
{
this.invokeStrings = invokeStrings ?? throw new ArgumentNullException();
for (int i = 0; i < invokeStrings.Length; i++) {
if (invokeStrings[i].Contains(" ")) {
throw new ArgumentException("Can't have spaces in command invocation strings.");
}
}
}
/// <summary>
@ -51,8 +56,8 @@ namespace RecrownedGTK.Tools.CommandProcessor
/// <summary>
/// Runs the command.
/// </summary>
/// <param name="arguments">arguments to be used. May be null.</param>
public abstract void Run(IUserInput userInput = null, IUserOutput userOutput = null, string[] arguments = null);
/// <param name="arguments">arguments to be used. Each string should be the argument input. May be null.</param>
public abstract void Run(IUserInput userInput = null, IUserOutput userOutput = null, params string[] arguments);
/// <summary>
/// Check if given argument is viable for command.