Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with the Reading Raw Data Rows Feature #47

Open
Endimion75 opened this issue Feb 10, 2016 · 2 comments
Open

Problem with the Reading Raw Data Rows Feature #47

Endimion75 opened this issue Feb 10, 2016 · 2 comments

Comments

@Endimion75
Copy link

There is a problem when you use try to read raw data fields using the form

public class MyDataRow : List<DataRowItem>, IDataRow
{
}

Then using the code:

IEnumerable<MyDataRow> products = cc.Read<MyDataRow>("products.csv", inputFileDescription);

The List gets populated with the corresponding rows from the txt file but the columns (DataRowItem object) are empty.

I used the debugger to follow the execution into the ReadData class. All the values are retrieved as expected and you can inspect them before they get yield returned. After this point they get lost

@Endimion75
Copy link
Author

As far as I can tell the problems is linked to the ReadRow function where the row variable gets its value and later passed to the obj value

if (readingRawDataRows)
{
   obj = row as T;
}

I think the obj/row value get rewritten with every iteration and as the obj variable gets passed as shallow copies it does not persists.

@Endimion75
Copy link
Author

I manage to make it work by "hacking" (not using the cool meaning of the word) the ReadData function in the CsvContext.cs

This is my changed, inside the "while (cs.ReadRow(row, charLengths))" loop

if (readingRawDataRows)
                            {
                                var newObj = new T() as IDataRow;
                                foreach (DataRowItem item in (IEnumerable) row)
                                    newObj.Add(new DataRowItem(item.Value, item.LineNbr));
                                obj = newObj as T;
                            }
                            else
                            {
                                obj = fm.ReadObject(row, ae);
                            }

So if it is reading raw data rows, it will instantiate a new Datarow object, making a deep copy of the row variable and passing it to the obj variable.

My understanding of generics is limited but I think this might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant