internal static ServiceQuery GetServiceQuery(Uri uri) { Contract.Requires(uri != null); NameValueCollection queryPartCollection = HttpUtility.ParseQueryString(uri.Query); List <ServiceQueryPart> serviceQueryParts = new List <ServiceQueryPart>(); foreach (string queryPart in queryPartCollection) { if (queryPart == null || !queryPart.StartsWith("$", StringComparison.Ordinal)) { // not a special query string continue; } foreach (string value in queryPartCollection.GetValues(queryPart)) { ServiceQueryPart serviceQueryPart = new ServiceQueryPart(queryPart.Substring(1), value); serviceQueryParts.Add(serviceQueryPart); } } // Query parts for OData need to be ordered $filter, $orderby, $skip, $top. For this // set of query operators, they are already in alphabetical order, so it suffices to // order by operator name. In the future if we support other operators, this may need // to be reexamined. serviceQueryParts = serviceQueryParts.OrderBy(p => p.QueryOperator).ToList(); ServiceQuery serviceQuery = new ServiceQuery() { QueryParts = serviceQueryParts, }; return(serviceQuery); }