/// <summary> /// Reads the query options from the given reader and returns the resulting service query. /// It assumes that the reader is positioned on a stream containing the query options. /// </summary> /// <param name="reader">Reader to the stream containing the query options.</param> /// <returns>Extracted service query.</returns> internal static ServiceQuery ReadServiceQuery(XmlReader reader) { List <ServiceQueryPart> serviceQueryParts = new List <ServiceQueryPart>(); bool includeTotalCount = false; while (reader.IsStartElement(MessageUtility.QueryOptionElementName)) { string name = reader.GetAttribute(MessageUtility.QueryNameAttribute); string value = reader.GetAttribute(MessageUtility.QueryValueAttribute); if (name.Equals(MessageUtility.QueryIncludeTotalCountOption, StringComparison.OrdinalIgnoreCase)) { bool queryOptionValue = false; if (Boolean.TryParse(value, out queryOptionValue)) { includeTotalCount = queryOptionValue; } } else { serviceQueryParts.Add(new ServiceQueryPart { QueryOperator = name, Expression = value }); } MessageUtility.ReadElement(reader); } ServiceQuery serviceQuery = new ServiceQuery() { QueryParts = serviceQueryParts, IncludeTotalCount = includeTotalCount }; return(serviceQuery); }