Created
May 24, 2012 08:18
-
-
Save coolya/2780186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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