これを達成するにはいくつかの手順が必要ですが、それほど難しいものではありません。まず、あなたが書いたものを解析する何らかのパーサーが必要です。各コマンドを読むには、var command = Console.ReadLine()
を使い、その行を解析してください。そして...メインロジックはこれを見ているベース(ソートの)を持つべきであるコマンドを実行します。
public static void Main(string[] args)
{
var exit = false;
while(exit == false)
{
Console.WriteLine();
Console.WriteLine("Enter command (help to display help): ");
var command = Parser.Parse(Console.ReadLine());
exit = command.Execute();
}
}
ソートのは、おそらくより複雑にそれを変更することができます。
Parser
とコマンドのコードは一種の単純です:
public interface ICommand
{
bool Execute();
}
public class ExitCommand : ICommand
{
public bool Execute()
{
return true;
}
}
public static Class Parser
{
public static ICommand Parse(string commandString) {
// Parse your string and create Command object
var commandParts = commandString.Split(' ').ToList();
var commandName = commandParts[0];
var args = commandParts.Skip(1).ToList(); // the arguments is after the command
switch(commandName)
{
// Create command based on CommandName (and maybe arguments)
case "exit": return new ExitCommand();
.
.
.
.
}
}
}
コードに関係なく、どのような「不正コマンド」ユーザーの種類が言う簡単なアプリケーションを。その後、コードを投稿し、より具体的な質問をしてください。 – Jon
私は間違いなく、どこから始めるのかわからないのでコードはありません... – keynesiancross