Skip to content

Instantly share code, notes, and snippets.

@coolya
Created May 24, 2012 08:18
Show Gist options
  • Save coolya/2780186 to your computer and use it in GitHub Desktop.
Save coolya/2780186 to your computer and use it in GitHub Desktop.
class GenricCmdLineParser
{
private Dictionary<string, Action<string>> Entries = new Dictionary<string, Action<string>>();
protected void Register(string arg, Action<string> valueSetter)
{
if (!Entries.ContainsKey(arg))
Entries.Add(arg.ToLowerInvariant(), valueSetter);
}
public void Parse(IEnumerable<String> args)
{
var enumerator = args.GetEnumerator();
while (enumerator.MoveNext())
{
string current = enumerator.Current.ToLowerInvariant();
if (Entries.ContainsKey(current))
{
if(enumerator.MoveNext())
Entries[current](enumerator.Current);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment