aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.ExcelExtensions/Rows.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-04-06 08:29:39 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-04-06 08:29:39 +0300
commitbfd7702939a162f62c46375762ceec9cd524f66a (patch)
treed496cd01929df64f013a9bfa6be7702afe30b4eb /RhSolutions.ExcelExtensions/Rows.cs
parent448af8ecd7bf9db070e090c4b434da693ba0ae89 (diff)
DI Refactoring
Diffstat (limited to 'RhSolutions.ExcelExtensions/Rows.cs')
-rw-r--r--RhSolutions.ExcelExtensions/Rows.cs23
1 files changed, 14 insertions, 9 deletions
diff --git a/RhSolutions.ExcelExtensions/Rows.cs b/RhSolutions.ExcelExtensions/Rows.cs
index 1c0bc0d..c6d4c01 100644
--- a/RhSolutions.ExcelExtensions/Rows.cs
+++ b/RhSolutions.ExcelExtensions/Rows.cs
@@ -4,35 +4,40 @@ namespace RhSolutions.ExcelExtensions;
public class Rows : IEnumerable<Row>
{
- public Range Range { get; }
public Table ParentTable { get; }
public int Length
{
- get => Range.Rows.Count;
+ get => _range.Rows.Count;
}
+ private Row[] _rows;
+ private Range _range;
- public Rows(Range range, Table parentTable)
+ public Rows(Table parentTable)
{
- Range = range;
ParentTable = parentTable;
+ _range = parentTable.Range;
+ _rows = new Row[Length];
}
public Row this[int index]
{
get
{
- if (index < 0 || index + 1 > Range.Rows.Count)
+ if (_rows[index] == null)
{
- throw new IndexOutOfRangeException();
+ _rows[index] = new Row(_range.Rows[index + 1], ParentTable);
+ return _rows[index];
+ }
+ else
+ {
+ return _rows[index];
}
-
- return new Row(Range.Rows[index + 1], ParentTable);
}
}
public IEnumerator<Row> GetEnumerator()
{
- return new RowsEnumerator(Range, ParentTable);
+ return new RowsEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();