RhSolutions-AddIn/RhSolutions.AddIn/ExcelTable/ExcelRowsEnumerator.cs
2023-03-31 15:27:31 +03:00

55 lines
984 B
C#

using System.Collections;
namespace RhSolutions.ExcelTable;
public class ExcelRowsEnumerator : IEnumerator<ExcelRow>
{
public Range Range { get; }
public ExcelTable ParentTable { get; }
private int position = 0;
object IEnumerator.Current
{
get
{
return Current;
}
}
public ExcelRow Current
{
get
{
try
{
return new ExcelRow(Range.Rows[position], ParentTable);
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
public ExcelRowsEnumerator(Range range, ExcelTable table)
{
Range = range;
ParentTable = table;
}
public bool MoveNext()
{
position++;
return (position <= Range.Rows.Count);
}
public void Reset()
{
position = 0;
}
public void Dispose()
{
}
}