Created
June 18, 2011 17:22
-
-
Save cburgdorf/1033292 to your computer and use it in GitHub Desktop.
Configuration parsing is fun
This file contains 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
/// <summary> | |
/// Splits up an configuration string and returns an Dictionary<string, string> | |
/// (e.g. "CommandName='FilesOnly'; Directory='C:\\Test\\'" becomes | |
/// new Dictionary<string, string> | |
/// { | |
/// {"commandname", "filesonly"}, | |
/// {"directory", "c:\\test\\"} | |
/// }) | |
/// </summary> | |
private Dictionary<string, string> ParseString(string configurationString) | |
{ | |
Func<string, string> sanitizeString = x => x.Trim().ToLower().Replace("'", ""); | |
return configurationString | |
.Split(';') | |
.Select(x => x.Split('=')) | |
.Where(x => x.Length == 2) | |
.ToDictionary(x => sanitizeString(x[0]), x => sanitizeString(x[1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment