本文整理汇总了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);
}
}