Example #1
0
        public static bool TryParse(XContainer xml, out GoodreadsBook result)
        {
            result = null;

            var bookNode = (xml is XElement && (xml as XElement).Name == "best_book") ? xml as XElement : xml.Descendants("best_book").FirstOrDefault();
            var idNode = (bookNode.Element("id")?.FirstNode as XText)?.Value;
            var titleNode = bookNode.Element("title");
            var authorNode = bookNode.Element("author");

            var title = titleNode?.Value;
            if (string.IsNullOrEmpty(title))
            {
                return false;
            }

            int id;
            if (idNode == null || !int.TryParse(idNode, out id))
            {
                id = int.MinValue;
            }

            GoodreadsAuthor author;
            if (authorNode == null || !GoodreadsAuthor.TryParse(authorNode, out author))
            {
                result = new GoodreadsBook(id, title);
            }
            else
            {
                result = new GoodreadsBook(id, title, author);
            }

            return true;
        }
Example #2
0
 private GoodreadsWork(int id, GoodreadsBook book, float averageRating)
     : base(id)
 {
     this.Book = book;
     this.AverageRating = averageRating;
 }
Example #3
0
 private GoodreadsWork(int id, GoodreadsBook book)
     : this(id, book, Single.NaN)
 {
 }