BooksGrid.Core/Managers/CsvCatalogReader.cs
/// <summary>
/// Converts line with fields to Book
/// </summary>
/// <param name="line">Book row</param>
/// <returns>Parsed book or null if error</returns>
Converts line with fields to Book
Converts line with fields to Book
public Book ParseBookRow(string line)
        {
            try
            {
                var fields = line.Split(fieldSeparator);
                var book = new Book
                {
                    Title = fields[0],
                    Author = fields[1],
                    Year = Convert.ToInt32(fields[2]),
                    Price = Convert.ToDouble(fields[3].Replace(',','.')), 
                    InStock = yesString.Equals(fields[4], StringComparison.InvariantCultureIgnoreCase),
                    Binding = fields[5],
                    Description = fields[6]
                };
                return book;
            }
            catch (Exception)
            {
                return null;
            }
        }
public Book ParseBookRow ( string line ) { try { var fields = line . Split ( fieldSeparator ) ; var book = new Book { Title = fields [ 0 ] , Author = fields [ 1 ] , Year = Convert . ToInt32 ( fields [ 2 ] ) , Price = Convert . ToDouble ( fields [ 3 ] . Replace ( ' ' , ' ' ) ) , InStock = yesString . Equals ( fields [ 4 ] , StringComparison . InvariantCultureIgnoreCase ) , Binding = fields [ 5 ] , Description = fields [ 6 ] } ; return book ; } catch ( Exception ) { return null ; } }
Converts line with fields to Book
Converts line with fields to Book
// Prices are stored with comma decimal // not a valid book
Parsed book or null if error
Parsed book or null if error
line
string
None