Create a command-only class

0

I just created a class of commands, so long as I did, I pulled the command class to the main class but I'm having an error

Command class:

public bool OnCommand(string[] args)
{
    if (args.Length > 1)
    {
        string a;
        if ((a = args[1]) != null)
        {
            if (a == "teste")
            {
                Console.WriteLine("teste");
                return true;
            }
        }
    }
    return true;
}

Main Class (I put only one part of the code, I found the other part unnecessary):

public void OnAction(Hashtable parameters)
{
      cmd.OnCommand();
}

Note: I have an error in this part: cmd.OnCommand(); says: There is no argument provided that corresponds to the required formal parameter "args"

    
asked by anonymous 27.08.2017 / 22:24

1 answer

0

Possibly args is a string and not a array of strings tries to pass this way:

cmd.OnCommand(new string[] { "ArgumentoUm", "ArgumentoDois", "ArgumentoTres" } )

If you want, add params :

 public bool OnCommand(params string[] args)
        {
            if (args.Length > 1)
            {
                string a;
                if ((a = args[1]) != null)
                {
                    if (a == "teste")
                    {
                        Console.WriteLine("teste");
                        return true;
                    }
                }
            }
            return true;
        }

So you can call the function without passing a new string like this:

cmd.OnCommand("ArgumentoUm", "ArgumentoDois", "ArgumentoTres" )
    
27.08.2017 / 22:31