I don't understand your Extensions problem, but I've used this code before to convert between a string and NameValueCollection - you can easily change it to use a StringDictionary:
public NameValueCollection StringToNameValueCollection(string KeyValueData, char KeyValueSeparator, char ItemSeparator)
{
NameValueCollection nvc = new NameValueCollection();
// split string into array of key/value pairs
string[] kvpairs = KeyValueData.Split(new char[]{ItemSeparator});
// add each pair to the collection
for (int i = 0; i < kvpairs.Length; i++)
{
if (!string.IsNullOrEmpty(kvpairs[i]))
{
if (kvpairs[i].Contains(KeyValueSeparator.ToString()))
{
// get the key
string k = kvpairs[i].Remove(kvpairs[i].IndexOf(KeyValueSeparator.ToString())).Trim();
// get the value
string v = kvpairs[i].Remove(0, kvpairs[i].IndexOf(KeyValueSeparator) + 1).Trim();
// add key/value if key is valid
if (!string.IsNullOrEmpty(k))
{
nvc.Add(k, v);
}
}
else
{
// no key/value separator in the pair, so add whole string as key and value
nvc.Add(kvpairs[i].Trim(), kvpairs[i].Trim());
}
}
}
return nvc;
}
Convert NameValueCollection to string:
public string NameValueCollectionToString(NameValueCollection nvc, char KeyValueSeparator, char ItemSeparator)
{
StringBuilder sb = new StringBuilder();
for(int i = 0; i < nvc.Count; i++)
{
if (i != 0)
{
sb.Append(ItemSeparator);
}
sb.Append(nvc.Keys[i]);
sb.Append(KeyValueSeparator);
sb.Append(nvc[i]);
}
return sb.ToString();
}
I've had to make a couple of changes from the code I used, but it should build. Note that it's not too forgiving - the separator characters cannot appear in either the 'key' or 'value' strings.