-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataLoader.cs
47 lines (41 loc) · 1.33 KB
/
DataLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using CsvHelper;
using CsvHelper.Configuration;
/******************************************************************
WARNING: There be dragons here.
This code reads the data.csv file to load the Show records.
You DO NOT need to understand this code.
******************************************************************/
namespace NinetiesTV
{
public class DataLoader
{
private static string _dataFilename = "data.csv";
public static List<Show> GetShows()
{
using(TextReader textReader = new StreamReader(_dataFilename))
{
using(CsvReader csv = new CsvReader(textReader, CultureInfo.CurrentCulture))
{
csv.Context.RegisterClassMap<ShowMap>();
return csv.GetRecords<Show>().ToList();
}
}
}
class ShowMap : ClassMap<Show>
{
public ShowMap()
{
Map(m => m.Name);
Map(m => m.StartYear);
Map(m => m.EndYear);
Map(m => m.Genres).Convert(arg => arg.Row.GetField("Genres").Split(";").ToList());
Map(m => m.EpisodeCount);
Map(m => m.ImdbRating);
}
}
}
}