0

I'm having problems getting the parameters of a method that is overriden in each class, as it says

Error 2 Argument 1: cannot convert from 'method group' to 'System.Reflection.MethodInfo' My project\Commands\Help.cs 44 61 MySteamBot

I have this code, where the error comes from. (This is part of the Help class, another child of the Command class.)

    private Dictionary<string, Type> GetParams(System.Reflection.MethodInfo method)
    {
        Dictionary<string, Type> parameters = new Dictionary<string, Type>();
        if (method != null && method.GetParameters().Length > 0)
        {
            foreach (ParameterInfo param in method.GetParameters())
            {
                parameters.Add(param.Name, param.ParameterType);
            }
        }

        return parameters;
    }

    public override void Run(string commandName)
    {
        foreach (KeyValuePair<string, Command> command in MySteamBot.Command.commandList)
        {
            if (command.Key.ToLower() == commandName.ToLower())
            {
                Console.WriteLine(command.Key);
                Console.WriteLine("\t{0}", command.Key);
                Console.WriteLine();
                Console.WriteLine("Arguments:");
                foreach (KeyValuePair<string, Type> param in GetParams(command.Value.Run))
                {
                    Console.WriteLine("\t{0}, {1}", param.Key, param.Value.ToString());
                };
            }
        }
    }

and this is my Command class, plus another one of its children.

class Say : Command
{
    protected new string name = "say";
    public new string desc = "Tells something to your friends list.";
    private int arguments = 1;
    public override int Arguments
    {
        get { return arguments; }
        set { }
    }

    public override void Run(string msg)
    {
        if (msg.Length <= 0) { return; }
        Program.SendMessageToFriendsList(msg);
    }
}

-----

class Command
{
    protected string name = "";
    public string desc = "Do some stuff.";
    private int arguments = 0;
    public virtual int Arguments {
        get { return arguments; }
        set { }
    }
    public List<Object> lastArguments;
    public static Dictionary<string, Command> commandList = new Dictionary<string, Command>();

    protected Command()
    {
        if (name == "") { return; }
        MySteamBot.Command.commandList.Add(name, this);
    }

    public virtual void Run(params Object[] args)
    {

    }
}

I get that apparently it wouldn't be able to get the parameters of a 'dynamic' method at runtime, but then how would I do it?

Sorry if this is too vague, I can give more details if needed.

Tenrys
  • 1
  • 2

0 Answers0