public static List <WineModel> WineList() { List <WineModel> list = new List <WineModel>(); var reader = new StreamReader(File.OpenRead("../wine.csv")); while (!reader.EndOfStream) { var value = reader.ReadLine(); WineModel newWine = FromCSV(Convert.ToString(value)); list.Add(newWine); } return(list); }
public static WineModel FromCSV(string csvData) { string[] values = Regex.Split(csvData, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); WineModel model = new WineModel { ID = values[0], Country = values[1], Description = values[2], Designation = values[3], Points = Convert.ToInt32(values[4]), Price = Convert.ToDecimal(values[5]), Region_1 = values[6], Region_2 = values[7], Variety = values[8], Winery = values[9] }; return(model); }