public static void Decode(this IDictionary<string, string> self, string encodedDictionary, char separator, char keyValueSplitter, DictionaryExtension.Encoder keyDecoder, DictionaryExtension.Encoder valueDecoder, bool endsWithSeparator) { if (encodedDictionary == null) { throw new ArgumentNullException("encodedDictionary"); } if (keyDecoder == null) { throw new ArgumentNullException("keyDecoder"); } if (valueDecoder == null) { throw new ArgumentNullException("valueDecoder"); } if (endsWithSeparator && encodedDictionary.LastIndexOf(separator) == encodedDictionary.Length - 1) { encodedDictionary = encodedDictionary.Substring(0, encodedDictionary.Length - 1); } string[] strArrays = encodedDictionary.Split(new char[] { separator }); for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; string[] strArrays1 = str.Split(new char[] { keyValueSplitter }); if (((int)strArrays1.Length == 1 || (int)strArrays1.Length > 2) && !string.IsNullOrEmpty(strArrays1[0])) { throw new ArgumentException("The request is not properly formatted.", "encodedDictionary"); } if ((int)strArrays1.Length != 2) { throw new ArgumentException("The request is not properly formatted.", "encodedDictionary"); } string str1 = keyDecoder(strArrays1[0].Trim()); string str2 = strArrays1[1].Trim(); char[] chrArray = new char[] { '\"' }; string str3 = valueDecoder(str2.Trim(chrArray)); try { self.Add(str1, str3); } catch (ArgumentException argumentException) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { str1 }; throw new ArgumentException(string.Format(invariantCulture, "The request is not properly formatted. The parameter '{0}' is duplicated.", objArray), "encodedDictionary"); } } }
public static string Encode(this IDictionary<string, string> self, char separator, char keyValueSplitter, DictionaryExtension.Encoder keyEncoder, DictionaryExtension.Encoder valueEncoder, bool endsWithSeparator) { if (keyEncoder == null) { throw new ArgumentNullException("keyEncoder"); } if (valueEncoder == null) { throw new ArgumentNullException("valueEncoder"); } StringBuilder stringBuilder = new StringBuilder(); foreach (KeyValuePair<string, string> keyValuePair in self) { if (stringBuilder.Length != 0) { stringBuilder.Append(separator); } stringBuilder.AppendFormat("{0}{1}{2}", keyEncoder(keyValuePair.Key), keyValueSplitter, valueEncoder(keyValuePair.Value)); } if (endsWithSeparator) { stringBuilder.Append(separator); } return stringBuilder.ToString(); }
public static void Decode(this IDictionary<string, string> self, string encodedDictionary, DictionaryExtension.Encoder decoder) { self.Decode(encodedDictionary, '&', '=', decoder, decoder, false); }
public static string Encode(this IDictionary<string, string> self, DictionaryExtension.Encoder encoder) { return self.Encode('&', '=', encoder, encoder, false); }