RhSolutions-AddIn/RhSolutions.ExcelExtensions/Rows.cs

45 lines
921 B
C#
Raw Normal View History

2023-03-31 15:27:31 +03:00
using System.Collections;
2023-04-01 15:58:42 +03:00
namespace RhSolutions.ExcelExtensions;
2023-03-31 15:27:31 +03:00
2023-04-01 15:58:42 +03:00
public class Rows : IEnumerable<Row>
2023-03-31 15:27:31 +03:00
{
2023-04-01 15:58:42 +03:00
public Table ParentTable { get; }
2023-03-31 15:27:31 +03:00
public int Length
{
2023-04-06 08:29:39 +03:00
get => _range.Rows.Count;
2023-03-31 15:27:31 +03:00
}
2023-04-06 08:29:39 +03:00
private Row[] _rows;
private Range _range;
2023-03-31 15:27:31 +03:00
2023-04-06 08:29:39 +03:00
public Rows(Table parentTable)
2023-03-31 15:27:31 +03:00
{
ParentTable = parentTable;
2023-04-06 08:29:39 +03:00
_range = parentTable.Range;
_rows = new Row[Length];
2023-03-31 15:27:31 +03:00
}
2023-04-01 15:58:42 +03:00
public Row this[int index]
2023-03-31 15:27:31 +03:00
{
get
{
2023-04-06 08:29:39 +03:00
if (_rows[index] == null)
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
_rows[index] = new Row(_range.Rows[index + 1], ParentTable);
return _rows[index];
}
else
{
return _rows[index];
2023-03-31 15:27:31 +03:00
}
}
}
2023-04-01 15:58:42 +03:00
public IEnumerator<Row> GetEnumerator()
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
return new RowsEnumerator(this);
2023-03-31 15:27:31 +03:00
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}