-
Notifications
You must be signed in to change notification settings - Fork 2
/
CsvRow.cs
54 lines (44 loc) · 1.21 KB
/
CsvRow.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
48
49
50
51
52
53
54
using System.Collections.Generic;
namespace CsvTools
{
public class CsvRow
{
private string[] _cells;
private CsvTable _table;
private Dictionary<string, ICsvColumn> _columnCache = new Dictionary<string, ICsvColumn>();
public CsvRow(string[] row, CsvTable table)
{
_cells = row;
_table = table;
}
public ICsvColumn this[int index]
{
get
{
return GetColumn(index);
}
}
public ICsvColumn this[string name]
{
get
{
return GetColumn(name);
}
}
private ICsvColumn GetColumn(int index)
{
string name = _table.GetHeader(index).Name;
return GetColumn(name);
}
private ICsvColumn GetColumn(string name)
{
ICsvColumn column;
if (_columnCache.TryGetValue(name, out column)) {
return _columnCache[name];
}
CsvHeader header = _table.GetHeader(name);
column = new CsvColumn(_cells[header.Index]);
return _columnCache[name] = column;
}
}
}