using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; namespace FLocal.Importer { public static class DictionaryConverter { public static string ToDump(Dictionary dict) { return string.Join(" ", (from kvp in dict select HttpUtility.UrlEncode(kvp.Key, ShallerConnector.encoding) + "=" + HttpUtility.UrlEncode(kvp.Value, ShallerConnector.encoding)).ToArray()); } public static Dictionary FromDump(string dump) { Dictionary result = new Dictionary(); foreach(var kvp in (from elem in dump.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) let parts = elem.Split(new char[] { '=' }, 2) select new KeyValuePair(HttpUtility.UrlDecode(parts[0], ShallerConnector.encoding), HttpUtility.UrlDecode(parts[1], ShallerConnector.encoding)))) { result[kvp.Key] = kvp.Value; } return result; } } }