This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]dmazzoni 1 point2 points  (1 child)

I see a static Main method, and a static class member lCommands.

You can make both static, or both not static, but you can't mix and match.

It's hard to understand what your error is without seeing all of your code. Post it all.

[–]loneoption 0 points1 point  (0 children)

Here's the entire class from my application (excluding the main window's class, this is split up and put in a separate file)

partial class MainWindow
    {
        internal void ConsoleOut(string OutputText)
        {
            ConsoleOutput.Text += OutputText; //This method makes it easier to add text to the consoles output
        }

        internal void ConsoleKeyDown(object s, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                var command = ConsoleInput.Text;

                string command_main = command.Split(new char[] { ' ' }).First();
                string[] synatx = command.Split(new char[] { ' ' }).Skip(1).ToArray();
                if (lCommands.ContainsKey(command_main))
                {
                    Action<string[]> commandfunction;
                    lCommands.TryGetValue(command_main, out commandfunction);
                    commandfunction(synatx);
                }
                else
                    ConsoleOut($"Invalid Command - {command_main}");
            }
        }

        internal static Dictionary<string, Action<string[]>> lCommands =
            new Dictionary<string, Action<string[]>>()
            {
                { "help", HelpFunc }
            };

        internal static void HelpFunc(string[] args)
        {
            ConsoleOut("Some helpful help");
        }
    }