How to import a CSV file with a space in the header using ServiceStack.Text

I use the ServiceStack.Text library to read from CSV files in C #.

I would like to know how to deserialize a CSV for objects where the CSV contains a space-separated space?

I use this code to deserialize CSV in empClass :

  List<empClass> objList = File.ReadAllText(filePath).FromCsv<List<empClass>>();

If I have a csv file like this

EmpId,Employee Name,Employee Address 
12,JohnSmith,123 ABC Street

and my class is like

public class empClass{
public string EmpId;
public string Employee_Name;
public string Employee_Address;
}

It fills in EmpId but does not fill in Employee Name and Employee Address , because it contains a blank space in the header.

We will be grateful if someone can help.

+4
source share
1 answer

POCO CSV, , , , ServiceStack.

, , :

[DataContract]
public class EmpClass
{
    [DataMember]
    public string EmpId { get; set; }
    [DataMember(Name="Employee Name")]
    public string EmployeeName  { get; set; }
    [DataMember(Name="Employee Address")]
    public string EmployeeAddress  { get; set; }
}
+2

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


All Articles