From bfd7702939a162f62c46375762ceec9cd524f66a Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 6 Apr 2023 08:29:39 +0300 Subject: DI Refactoring --- RhSolutions.ExcelExtensions/Rows.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'RhSolutions.ExcelExtensions/Rows.cs') 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 { - 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 GetEnumerator() { - return new RowsEnumerator(Range, ParentTable); + return new RowsEnumerator(this); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); -- cgit v1.2.3