Apache.NMS.Util.URISupport.ParseQuery C# (CSharp) Method

ParseQuery() public static method

Parse a Uri query string of the form ?x=y&z=0 into a map of name/value pairs.
public static ParseQuery ( String query ) : StringDictionary
query String The query string to parse. This string should not contain /// Uri escape characters.
return System.Collections.Specialized.StringDictionary
        public static StringDictionary ParseQuery(String query)
        {
            StringDictionary map = new StringDictionary();

            if(String.IsNullOrEmpty(query))
            {
                return EmptyMap;
            }

            // strip the initial "?"
            if(query.StartsWith("?"))
            {
                query = query.Substring(1);
            }

            // split the query into parameters
            string[] parameters = query.Split('&');
            foreach(string pair in parameters)
            {
                if(pair.Length > 0)
                {
                    string[] nameValue = pair.Split('=');

                    if(nameValue.Length != 2)
                    {
                        throw new NMSException(string.Format("Invalid Uri parameter: {0}", query));
                    }

                    map[nameValue[0]] = nameValue[1];
                }
            }

            return map;
        }