RhSolutions-AddIn/RhSolutions.ExcelExtensions/Columns.cs

49 lines
1.1 KiB
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 Columns : IEnumerable<Column>
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.Columns.Count;
2023-03-31 15:27:31 +03:00
}
2023-04-06 08:29:39 +03:00
private Column[] _columns;
private Range _range;
2023-03-31 15:27:31 +03:00
2023-04-06 08:29:39 +03:00
public Columns(Table parentTable)
2023-03-31 15:27:31 +03:00
{
ParentTable = parentTable;
2023-04-06 08:29:39 +03:00
_range = parentTable.Range;
_columns = new Column[Length];
2023-03-31 15:27:31 +03:00
}
2023-04-01 15:58:42 +03:00
public Column this[int index]
2023-03-31 15:27:31 +03:00
{
get
{
2023-04-06 08:29:39 +03:00
if (index < 0 || index >= Length)
2023-03-31 15:27:31 +03:00
{
throw new IndexOutOfRangeException();
}
2023-04-06 08:29:39 +03:00
if (_columns[index] == null)
{
_columns[index] = new Column(_range.Columns[index + 1], ParentTable);
return _columns[index];
}
else
{
return _columns[index];
}
2023-03-31 15:27:31 +03:00
}
}
2023-04-01 15:58:42 +03:00
public IEnumerator<Column> GetEnumerator()
2023-03-31 15:27:31 +03:00
{
2023-04-06 08:29:39 +03:00
return new ColumnsEnumerator(this);
2023-03-31 15:27:31 +03:00
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}