当前位置: 首页>>代码示例>>C#>>正文


C# Commands.helptopic方法代码示例

本文整理汇总了C#中Commands.helptopic方法的典型用法代码示例。如果您正苦于以下问题:C# Commands.helptopic方法的具体用法?C# Commands.helptopic怎么用?C# Commands.helptopic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Commands的用法示例。


在下文中一共展示了Commands.helptopic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessInput


//.........这里部分代码省略.........
                        // The closing quotation mark is not within the same parameter.
                        bool found = false;
                        int j = i + 1;
                        // Search for the closing mark.
                        while (j < parameters.Count)
                        {
                            param += " " + parameters[j];
                            if (param.Contains("\""))
                            {
                                found = true;
                                break;
                            }

                            j++;
                        }

                        if (!found)
                        {
                            DebugPrint("Syntax error: No closing quotation mark.");
                            return;
                        }
                        else
                        {
                            // Remove the extra parameters that we just merged.
                            int toRemove = (j - i) + (i + 1);
                            for (int k = i + 1; k < toRemove; k++)
                            {
                                parameters.RemoveAt(i + 1);
                            }
                        }
                    }
                }

                parameters[i] = param.Replace("\"", "");
            }

            string command = parameters[0].ToString().ToLower();
            parameters.RemoveAt(0);

            // Print a preview of what the command looks like in our eyes.
            System.Text.StringBuilder buffer = new System.Text.StringBuilder();
            buffer.Append("> ");
            buffer.Append(command);
            buffer.Append('(');
            for (int i = 0; i < parameters.Count; i++)
            {
                buffer.Append(parameters[i]);
                if (i + 1 < parameters.Count)
                {
                    buffer.Append(", ");
                }
            }
            buffer.Append(");");

            string formattedMessage = buffer.ToString();
            DebugPrint(formattedMessage);
            history.Enqueue(formattedMessage.Substring(2));
            while (history.Count > HistoryLimit)
            {
                history.Dequeue();
            }

            // Attempt to find the method by the given name.
            Commands commands = new Commands(this, DebugPrint);
            MethodInfo[] methods = typeof(Commands).GetMethods();
            MethodInfo method = null;
            foreach (MethodInfo testMethod in methods)
            {
                if (testMethod.Name == command && testMethod.GetParameters().Length == parameters.Count)
                {
                    method = testMethod;
                    break;
                }
            }

            //MethodInfo method = typeof(Commands).GetMethod(command);
            if (method == null)
            {
                DebugPrint(
                    "Command \"{0}\" is not recognized. Type \"help()\" for help.",
                    command);
                return;
            }

            int numberOfParameters = method.GetParameters().Length;
            if (parameters.Count != numberOfParameters)
            {
                commands.helptopic(command);
                return;
            }

            try
            {
                method.Invoke(commands, parameters.ToArray());
            }
            catch (Exception e)
            {
                DebugPrint("Syntax error: {0}", e.Message);
            }
        }
开发者ID:summer-of-software,项目名称:vtank,代码行数:101,代码来源:GameConsole.cs


注:本文中的Commands.helptopic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。