static DictionaryExtension()
 {
     DictionaryExtension.DefaultDecoder = new DictionaryExtension.Encoder(Base64UrlDecode);
     DictionaryExtension.DefaultEncoder = new DictionaryExtension.Encoder(Base64UrlEncode);
     DictionaryExtension.NullEncoder = new DictionaryExtension.Encoder(DictionaryExtension.NullEncode);
 }
Ejemplo n.º 2
0
 public static void Decode(this System.Collections.Generic.IDictionary <string, string> self, string encodedDictionary, char separator, char keyValueSplitter, DictionaryExtension.Encoder keyDecoder, DictionaryExtension.Encoder valueDecoder, bool endsWithSeparator)
 {
     if (encodedDictionary == null)
     {
         throw new System.ArgumentNullException("encodedDictionary");
     }
     if (keyDecoder == null)
     {
         throw new System.ArgumentNullException("keyDecoder");
     }
     if (valueDecoder == null)
     {
         throw new System.ArgumentNullException("valueDecoder");
     }
     if (endsWithSeparator && encodedDictionary.LastIndexOf(separator) == encodedDictionary.Length - 1)
     {
         encodedDictionary = encodedDictionary.Substring(0, encodedDictionary.Length - 1);
     }
     string[] array = encodedDictionary.Split(new char[]
     {
         separator
     });
     for (int i = 0; i < array.Length; i++)
     {
         string   text   = array[i];
         string[] array2 = text.Split(new char[]
         {
             keyValueSplitter
         });
         if ((array2.Length == 1 || array2.Length > 2) && !string.IsNullOrEmpty(array2[0]))
         {
             throw new System.ArgumentException("The request is not properly formatted.", "encodedDictionary");
         }
         if (array2.Length != 2)
         {
             throw new System.ArgumentException("The request is not properly formatted.", "encodedDictionary");
         }
         string text2 = keyDecoder(array2[0].Trim());
         string value = valueDecoder(array2[1].Trim().Trim(new char[]
         {
             '"'
         }));
         try
         {
             self.Add(text2, value);
         }
         catch (System.ArgumentException)
         {
             string message = string.Format(System.Globalization.CultureInfo.InvariantCulture, "The request is not properly formatted. The parameter '{0}' is duplicated.", new object[]
             {
                 text2
             });
             throw new System.ArgumentException(message, "encodedDictionary");
         }
     }
 }
Ejemplo n.º 3
0
 public static string Encode(this System.Collections.Generic.IDictionary <string, string> self, char separator, char keyValueSplitter, DictionaryExtension.Encoder keyEncoder, DictionaryExtension.Encoder valueEncoder, bool endsWithSeparator)
 {
     if (keyEncoder == null)
     {
         throw new System.ArgumentNullException("keyEncoder");
     }
     if (valueEncoder == null)
     {
         throw new System.ArgumentNullException("valueEncoder");
     }
     System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
     foreach (System.Collections.Generic.KeyValuePair <string, string> current in self)
     {
         if (stringBuilder.Length != 0)
         {
             stringBuilder.Append(separator);
         }
         stringBuilder.AppendFormat("{0}{1}{2}", keyEncoder(current.Key), keyValueSplitter, valueEncoder(current.Value));
     }
     if (endsWithSeparator)
     {
         stringBuilder.Append(separator);
     }
     return(stringBuilder.ToString());
 }
Ejemplo n.º 4
0
 public static void Decode(this System.Collections.Generic.IDictionary <string, string> self, string encodedDictionary, DictionaryExtension.Encoder decoder)
 {
     self.Decode(encodedDictionary, '&', '=', decoder, decoder, false);
 }
Ejemplo n.º 5
0
 public static string Encode(this System.Collections.Generic.IDictionary <string, string> self, DictionaryExtension.Encoder encoder)
 {
     return(self.Encode('&', '=', encoder, encoder, false));
 }