示例#1
0
        /// <summary>
        /// Converts <paramref name="query" /> to a Dictionary.
        /// </summary>
        /// <param name="query">Query string to convert.</param>
        /// <returns>Dictionary representing a Uri query.</returns>
        public static IDictionary <string, string> ToDictionary(string query)
        {
            if (string.IsNullOrEmpty(query) || query == "?")
            {
                return(new Dictionary <string, string>());
            }

            var pairs = ToNameValueArray(query);

            var dict = new Dictionary <string, string>(pairs.Length);

            foreach (var pair in pairs)
            {
                var keyValuePair = QueryKeyValuePairFactory.Create(pair);

                dict.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(dict);
        }
示例#2
0
        /// <summary>
        /// Converts <paramref name="query" /> to a NameValueCollection.
        /// </summary>
        /// <param name="query">Query string to convert.</param>
        /// <returns>NameValueCollection representing a Uri query.</returns>
        public static NameValueCollection ToNameValueCollection(string query)
        {
            if (string.IsNullOrEmpty(query) || query == "?")
            {
                return(new NameValueCollection());
            }

            var pairs = ToNameValueArray(query);

            var collection = new NameValueCollection(pairs.Length);

            foreach (var pair in pairs)
            {
                var keyValuePair = QueryKeyValuePairFactory.Create(pair);

                collection.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(collection);
        }