Giving parameters to a Func.

Hey, I am trying to make a command line that gets a string and the I call a function based off of said string. I am trying to use dictionaries because I think that'll be better than a super long list of if statements. But, I have run into an issue where I cannot figure out how to give a Funt parameters. Here's the code:
namespace example
{
  public static class CommandLine
  {
    // Dictionary with all valid commands and then the corresponding method.
    private static Dictionary<string, Func<string>> validCommands = new Dictionary<string, Func<string>>()
    {
      {"test", TestMethod}
    };

      // Called from else where in the program with the raw command string. Ex: "/test"
      public static string CommandParser(string rawCommand)
      {
        if (rawCommand != "")
        {
          // Removes the '/' from the string and split it to an array of words.
          string[] formattedCommand = rawCommand.Remove(0, 1).Split(" ");
          try
          {
            // Finds the command and runs the appropiate function.
            return $"Output: {validCommands[formattedCommand[0]].Invoke()}";
          }
          catch (KeyNotFoundException)
          {
            // If command isn't found this will be printed.
            return $"Invalid command \"{rawCommand}\".";
          }
        }
        else
        {
          // Returns an empty string to allow for new lines.
          return "";
        }
    }

    public static string TestMethod()
    {
      return "Yay it worked";
    }
  }
}

My question is, how do I modify this code so I can add parameters to TestMethod and still call it in this way. Or even if there is a better/cleaner way to build something like this I'll look into what ever information I'm provided. Thank you so much for any and all assistance.
Was this page helpful?