返回一个字符串数组?

Luc*_*rus 1 c# system server-side mmo

所以在我的游戏服务器上,我们有服务器端命令。我想知道是否可以转动这个

public string Command
{
    get { return "g"; }
}
Run Code Online (Sandbox Code Playgroud)

变成这样

public string Command
{
    get { return "g", "guild", "group"; }
}
Run Code Online (Sandbox Code Playgroud)

这是命令接口代码

internal interface ICommand
{
    string Command { get; }
    int RequiredRank { get; }
    void Execute(Player player, string[] args);
}
Run Code Online (Sandbox Code Playgroud)

这是命令处理程序的代码
第 1 部分:

ProcessCmd(x[0].Trim('/'), x.Skip(1).ToArray());
Run Code Online (Sandbox Code Playgroud)

第2部分:

private void ProcessCmd(string cmd, string[] args)
{
    if (cmds == null)
    {
        cmds = new Dictionary<string, ICommand>();
        var t = typeof (ICommand);
        foreach (var i in t.Assembly.GetTypes())
            if (t.IsAssignableFrom(i) && i != t)
            {
                var instance = (ICommand) Activator.CreateInstance(i);
                cmds.Add(instance.Command, instance);
            }
    }

    ICommand command;
    if (!cmds.TryGetValue(cmd, out command))
    {
        psr.SendPacket(new TextPacket
        {
            BubbleTime = 0,
            Stars = -1,
            Name = "*Error*",
            Text = "Unknown Command!"
        });
        return;
    }
    try
    {
        ExecCmd(command, args);
    }
    catch (Exception e)
    {
        Console.Out.WriteLine(e);
        psr.SendPacket(new TextPacket
        {
            BubbleTime = 0,
            Stars = -1,
            Name = "*Error*",
            Text = "Error when executing the command!"
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

pid*_*pid 5

你要这个:

public string[] Commands
{
    get { return new string[] {"g", "guild", "group"}; }
}
Run Code Online (Sandbox Code Playgroud)

从这个开始。它会产生您应该修复的错误,并且通过推进修复,您将重构一个很好的代码部分,例如ICommand界面。