aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.ExcelExtensions/Row.cs
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.ExcelExtensions/Row.cs')
-rw-r--r--RhSolutions.ExcelExtensions/Row.cs51
1 files changed, 36 insertions, 15 deletions
diff --git a/RhSolutions.ExcelExtensions/Row.cs b/RhSolutions.ExcelExtensions/Row.cs
index 32617b4..01df2e4 100644
--- a/RhSolutions.ExcelExtensions/Row.cs
+++ b/RhSolutions.ExcelExtensions/Row.cs
@@ -1,33 +1,54 @@
-using System.Collections;
+namespace RhSolutions.ExcelExtensions;
-namespace RhSolutions.ExcelExtensions;
-
-public sealed class Row : Table, IEnumerable<TableCell>
+public sealed class Row
{
+ public Table ParentTable { get; }
public int Index
{
- get => Range.Row - ParentTable.Range.Row;
+ get => _range.Row - ParentTable.Range.Row;
}
public int Length
{
- get => Range.Columns.Count;
+ get => _range.Columns.Count;
}
+ private readonly Cell[] _cells;
+ private readonly Range _range;
- public Row(Range range, Table table) : base(range, table)
+ public Row(Range range, Table table)
{
- Range = range;
- ParentTable = table;
+ _cells = new Cell[range.Columns.Count];
+ _range = range;
+ ParentTable = table ??
+ throw new ArgumentNullException("table");
}
- public TableCell this[int index]
+ public Cell this[int index]
{
- get => new(Range.Cells[1, index + 1], ParentTable);
+ get
+ {
+ if (index < 0 || index >= Length)
+ {
+ throw new IndexOutOfRangeException();
+ }
+
+ if (_cells[index] == null)
+ {
+ _cells[index] = new Cell(_range.Cells[1, index + 1], ParentTable);
+ return _cells[index];
+ }
+ else
+ {
+ return _cells[index];
+ }
+ }
}
- public IEnumerator<TableCell> GetEnumerator()
+ public Cell this[string header]
{
- return new RowEnumerator(Range, ParentTable);
+ get
+ {
+ int columnIndex = ParentTable.ColumnByHeader(header).Index;
+ return this[columnIndex];
+ }
}
-
- IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}