Example #1
0
        /// <summary>
        /// Serializes the key-value pairs into a query string, using the specified separator. URL encoding of keys/values is automatically performed. Null values are not written (only their key is written). If there are no parameters, an empty string will be returned.
        /// </summary>
        /// <param name="separator"></param>
        /// <returns></returns>
        public string ToString(QueryStringSeparator separator) => String.Join(GetSeparatorString(separator), this.Select(

                                                                                  pair =>

                                                                                  // Key
                                                                                  UrlEncode(pair.Name) +

                                                                                  // Write value if not null
                                                                                  ((pair.Value == null) ? "" : ("=" + UrlEncode(pair.Value)))

                                                                                  ));
Example #2
0
        private static string GetSeparatorString(QueryStringSeparator separator)
        {
            switch (separator)
            {
            case QueryStringSeparator.Ampersand:
                return("&");

            case QueryStringSeparator.Semicolon:
                return(";");

            default:
                throw new NotImplementedException(separator.ToString());
            }
        }