aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.ExcelExtensions/Rows.cs
blob: c6d4c01ea8419c61f74e6d1123f6e6b9ea819c45 (plain)
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
using System.Collections;

namespace RhSolutions.ExcelExtensions;

public class Rows : IEnumerable<Row>
{
    public Table ParentTable { get; }
    public int Length
    {
        get => _range.Rows.Count;
    }
    private Row[] _rows;
    private Range _range;

    public Rows(Table parentTable)
    {
        ParentTable = parentTable;
        _range = parentTable.Range;
        _rows = new Row[Length];
    }

    public Row this[int index]
    {
        get
        {
            if (_rows[index] == null)
            {
                _rows[index] = new Row(_range.Rows[index + 1], ParentTable);
                return _rows[index];
            }
            else
            {
                return _rows[index];
            }
        }
    }

    public IEnumerator<Row> GetEnumerator()
    {
        return new RowsEnumerator(this);
    }

    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}