CsvHelper: no item is displayed for type

I am using CsvHelper 4.0.3 .

I have a nested class defined as follows:

private class CsvLine {
    public string Solution;
    public string Project;
    public string DependsOnProject;
    public string Weight;
    public string DependsOnPackage;
    public string PackageVersion;
}

My .csv file that I want to parse with CsvHelperhas the following field names:

Solution,Project,DependsOnProject,Weight,DependsOnPackage,PackageVersion

Here is my code:

TextReader readFile = new StreamReader(dependenciesCsvFilePath);
var csvReader = new CsvReader(readFile);
IEnumerable<CsvLine> records = csvReader.GetRecords<CsvLine>();

As per the documentation here , the code above should work.

However, when I check records, I see a message No members are mapped for type 'ParentClass+CsvLine'.

I changed the availability CsvLinefrom privateto public, but that didn't matter.

What have I done wrong?

EDIT: I tried to expose the class CsvLineand make it publicly available, but that didn't help either.

EDIT: Nkosi; , records - : " ". CSV , .

:

Solution,Project,DependsOnProject,Weight,DependsOnPackage,PackageVersion
FOD.sln,ABC.DEF,IMS.ABC,1,,
FOD.sln,ABC.DEF,IMS.DEF,1,,
FOD.sln,ABC.DEF,IMS.GHI,1,,
FOD.sln,ABC.DEF,IMS.JKL,1,,

EDIT: ! Nkosi Panagiotis .

+6
4

, .

public class CsvLine {
    public string Solution { get; set; }
    public string Project { get; set; }
    public string DependsOnProject { get; set; }
    public string Weight { get; set; }
    public string DependsOnPackage { get; set; }
    public string PackageVersion { get; set; }
}

csv.

CsvHelper:

+9

Nkosi , CsvHelper .

Enumeration yielded no results . . , , . IEnumerable foreach .ToArray() .ToList() , :

var records = csvReader.GetRecords<CsvLine>();
foreach(var record in records)
{
     ...
}

var records = csvReader.GetRecords<CsvLine>().ToArray();

IEnumerable Watch, Quick Watch Immediate, results , :

records,results

, IEnumerable .

7 Visual Studio 2017

+6

:

  • char.
  • .

:

var conf = new CsvHelper.Configuration.Configuration();
conf.Delimiter = ",";
conf.Quote = '\'';
var csv = new CsvHelper.CsvReader(reader, conf);
var rows = csv.GetReads<MyClass>();
+1

There is a simpler solution to the problem, this is just one line of code. You must tell csvhelper to look at your fields.

using (var csv = new CsvWriter(writer))
{
    csv.Configuration.MemberTypes = CsvHelper.Configuration.MemberTypes.Fields;
.....
}
0
source

Source: https://habr.com/ru/post/1688539/


All Articles