using ConsoleApp1.model; using CsvHelper.Configuration; using CsvHelper; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1.read { internal class ReadToCSV { public List ImportToCsv(string path) { List data = new List(); using (StreamReader reader = new StreamReader(path)) { string line; while ((line = reader.ReadLine()) != null) { string[] values = line.Split(','); T item = Activator.CreateInstance(); var properties = typeof(T).GetProperties(); for (int i = 0; i < properties.Length; i++) { properties[i].SetValue(item, Convert.ChangeType(values[i], properties[i].PropertyType), null); } data.Add(item); } } return data; } } }