MikeStall / DataTable

Class library for working with tabular data, especially CSV files
Apache License 2.0
150 stars 63 forks source link

Bug parsing files containing a single column #2

Closed munissor closed 12 years ago

munissor commented 12 years ago

Hi Mike,

first of all thanks for your library. At the moment I'm using it to parse csv files containing optional columns and it works very well.

There is an issue when the CSV file contains only one column (so the separator is missing ), I receive an exception reading the rows of the file.

Following a program that reproduces the issue

using System;
using System.IO;
using DataAccess;
using System.Linq;

namespace TestCsvTools
{
    class Program
    {
        public class RowData
        {
            public string Column1 { get; set; }
            public string Column2 { get; set; }
        }

        public static void Main(string[] args)
        {
            string data = @"column2
row1
row2
";
            using(var rd = new StringReader( data ) )
            {
                var dt = DataTable.New.Read( rd );
                var rows = dt.RowsAs<RowData>().ToArray();
            }
        }
    }
}

I might work on a solution for the bug and submit a patch if you will accept it.

Thanks Riccardo

MikeStall commented 12 years ago

I'd accept patches. I'd expect the change to be in the Reader class: https://github.com/MikeStall/DataTable/blob/master/Sources/DataAccess/Readers.cs

The tests are in: https://github.com/MikeStall/DataTable/tree/master/Sources/DataTableTests

MikeStall commented 12 years ago

I fixed some build issues so that you can build and run tests from the GitHub sources. So it should be easy for you to create a patch for these issues. Else, I'll fix these issues in a few days.

MikeStall commented 12 years ago

It looks like it reads in just fine (DataTable.New.Read succeeds), but the problem is parsing to a strongly typed structure (dt.RowsAs<> fails)

MikeStall commented 12 years ago

Just pushed a fix. Incorporated the above test case as my regression test.