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

Fixing issue with less number of columns in CSV than the Class Members #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

himanshugupta-mt
Copy link

@himanshugupta-mt himanshugupta-mt commented Jun 16, 2017

The issue I encountered was the object defined like

class Product
{
        [CsvColumn(Name = "A")]
	public int A { get; set; }
        [CsvColumn(Name = "B" ,CanBeNull = false)]
	public string B { get; set; }
	[CsvColumn(Name = "C", CanBeNull = false)]
	public string C { get; set; }
}

CsvFileDescription inputFileDescription = new CsvFileDescription
{
      SeparatorChar = ',',
      FirstLineHasColumnNames = true,
      EnforceCsvColumnAttribute = true
};

CsvContext cc = new CsvContext();
IEnumerable<Product> products = cc.Read<Product>("a.csv", inputFileDescription);


and a.csv looks like this

B,C
b,c

The library does not handle this case correctly. It still complains that the value of Column C is not provided.

@tonyjunio
Copy link

Hi! I've been trying to look for this solution. I thought the index error will be fixed by IgnoreUnknownColumns but turned out the error is because my model has more fields than the csv.

My scenario is this. I defined one model class with all possible fields because my csv report files, although they are of the same report type, can have different available columns.

Anyhoo, I will try this updates you have. Many thanks! ^__^

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

Successfully merging this pull request may close these issues.

2 participants