Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active December 13, 2015 18:39
Show Gist options
  • Save yetanotherchris/4957373 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4957373 to your computer and use it in GitHub Desktop.
CommandOptions usage example
static void Main(string[] args)
{
string input = "";
MyHandler handler = new MyHandler();
CommandOptions options = new CommandOptions();
options.Add("show", handler.Show)
.Add("name", v => handler.Name(v))
.Add("age", v => handler.Age(v))
while (input != "quit" && input != "exit")
{
if (input == "cls" || input == "clear")
{
System.Console.Clear();
}
else
{
if (!string.IsNullOrEmpty(input))
{
if (options.Parse(input))
{
System.Console.WriteLine(handler.OutputMessage);
}
else
{
System.Console.WriteLine("I didn't understand that command");
}
}
}
System.Console.Write(">");
input = System.Console.ReadLine();
}
}
public class MyHandler
{
public string OutputMessage { get; set; }
public void Show()
{
OutputMessage = "Do something with the Show command, list SQL tables for example";
}
public void Name(string[] args)
{
OutputMessage = string.Format("{0} is your name",args[0]));
}
public void Age(string[] args)
{
OutputMessage = string.Format("{0} is your age",args[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment