RhSolutions-AddIn/RhSolutions.ExcelExtensions/Rows.cs
2023-04-06 08:29:39 +03:00

45 lines
921 B
C#

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();
}