Ejemplo n.º 1
0
        public static QueryParamCollection Parse(string queryString)
        {
            QueryParamCollection result = new QueryParamCollection();

            if (string.IsNullOrEmpty(queryString))
            {
                return(result);
            }

            queryString = queryString.TrimStart('?').Split('?').Last();

            var pairs = (
                from keyValue in queryString.Split('&')
                let pair = keyValue.Split('=')
                           let key = pair[0]
                                     let value = pair.Length >= 2 ? TrexUri.DecodeQueryParamValue(pair[1]) : ""
                                                 group value by key into g
                                                 select new { Key = g.Key, Values = g.ToArray() });

            foreach (var g in pairs)
            {
                if (g.Values.Length == 1)
                {
                    result.Add(g.Key, g.Values[0]);
                }
                else
                {
                    result.Add(g.Key, g.Values);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public TrexUri(string baseUri)
        {
            if (baseUri == null)
            {
                throw new ArgumentNullException("baseUri cannot be null");
            }

            string[] parts = baseUri.Split('?');
            Path        = parts[0];
            QueryParams = QueryParamCollection.Parse(parts.Length > 1 ? parts[1] : "");
        }