Beispiel #1
0
        /// <summary>
        /// XMLs the deserialize list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="response">The response.</param>
        /// <returns></returns>
        /// <exception cref="Redmine.Net.Api.Exceptions.RedmineException">could not deserialize:  + response</exception>
        private static PaginatedObjects <T> XmlDeserializeList <T>(string response)
            where T : class, new()
        {
            if (string.IsNullOrEmpty(response))
            {
                throw new RedmineException("could not deserialize: " + response);
            }

            using (System.IO.StringReader stringReader = new System.IO.StringReader(response))
            {
                using (System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(stringReader))
                {
                    xmlReader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
                    xmlReader.Read();
                    xmlReader.Read();

                    int totalItems = xmlReader.ReadAttributeAsInt(RedmineKeys.TOTAL_COUNT);

                    System.Collections.Generic.List <T> result = xmlReader.ReadElementContentAsCollection <T>();
                    return(new PaginatedObjects <T>()
                    {
                        TotalCount = totalItems,
                        Objects = result
                    });
                }
            }
        }