C# dictionary conversion for JSON
Today I needed to send a JSON friendly dictionary to the serialiser. LINQ came to the (writing it the short way) rescue.
Dictionary<T, T> dictionary = COM.Layer.GetTheDictionary(arg);
// convert
Dictionary<string, string> jsonDictionary = dictionary.ToDictionary(p => p.Key.ToString(), p => p.Value.ToString());
If you have complex <T> types, you could override ToString() add your own conversion to make sure everything is happy.
return jsonDictionary.ToJSON(); // ToJSON() string extension method
Thursday Jan 13th