private static ToplistBlock ConvertXElementToBlock(XElement xmlBlock) { xmlBlock.ThrowIfNull(nameof(xmlBlock)); string title = XDocumentParser.GetAttributeValue(xmlBlock, nameof(ToplistBlock.Title)); int number = XDocumentParser.GetAttributeValue <int>(xmlBlock, nameof(ToplistBlock.Number)); XElement?itemsXml = XDocumentParser.FindSubelement(xmlBlock, nameof(ToplistBlock.Items)); if (itemsXml is null) { throw new ArgumentException( "Invalid strcuture of XML document: cannot find toplist items block.", nameof(xmlBlock) ); } var result = new ToplistBlock(title, number); result.UpdateItems( XDocumentParser.FindSubelements(itemsXml) .Select(xmlItem => ConvertXElementToItem(xmlItem, result)) .ToList() ); return(result); }
internal IReadOnlyList <ToplistBlock> ConvertXElementsToBlocks() { IReadOnlyList <XElement> xmlBlocks = XDocumentParser.FindSubelements(Blocks).ToList(); var blocks = new List <ToplistBlock>(xmlBlocks.Count); foreach (XElement xmlBlock in xmlBlocks) { blocks.Add(ConvertXElementToBlock(xmlBlock)); } return(blocks); }