/// <summary> /// Finds a command by its name and returns it, but returns null if no command was found. /// </summary> public CustomCommand FindCommand(string name) { string commandName = _table.CommandNames.FirstOrDefault(n => string.Equals(name, n, StringComparison.InvariantCultureIgnoreCase)); if (commandName == null) { return(null); } string json = _table.Get(commandName); try { return(JsonConvert.DeserializeObject <CustomCommand>(json)); } catch { // The deserialization failed because the command has syntax errors. return(_errorResponse); } }
/// <summary> /// Finds a command by its name and returns it, but returns null if no command was found. /// </summary> public CustomCommand FindCommand(string name) { // Compares name agains regexes storred in command names, ^ and $ is used to ensure that match can't be satisfied by part of the name string commandName = _table.CommandNames.FirstOrDefault(n => Regex.IsMatch(name, $"^{n}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)); if (commandName == null) { return(null); } string json = _table.Get(commandName); try { return(JsonConvert.DeserializeObject <CustomCommand>(json)); } catch { // The deserialization failed because the command has syntax errors. return(_errorResponse); } }