private Board ParseBoard(XDocument document) { Board board = new Board(); IEnumerable<XElement> chessPieces = document.Descendants("chessPiece"); foreach (XElement element in chessPieces) { XAttribute type = element.Attribute("type"); XAttribute color = element.Attribute("color"); XAttribute column = element.Attribute("column"); XAttribute row = element.Attribute("row"); if (type != null && color != null && column != null && row != null) { Color pieceColor = (Color)Enum.Parse(typeof(Color), color.Value, true); string letter = column.Value; int rowNumber = int.Parse(row.Value); ChessPiece piece = TypeToPiece(type.Value, pieceColor); int index = board.GetIndexByPosition(String.Concat(letter, rowNumber)); board[index] = piece; } } return board; }