diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2023-04-06 08:29:39 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2023-04-06 08:29:39 +0300 |
commit | bfd7702939a162f62c46375762ceec9cd524f66a (patch) | |
tree | d496cd01929df64f013a9bfa6be7702afe30b4eb /RhSolutions.ExcelExtensions/Columns.cs | |
parent | 448af8ecd7bf9db070e090c4b434da693ba0ae89 (diff) |
DI Refactoring
Diffstat (limited to 'RhSolutions.ExcelExtensions/Columns.cs')
-rw-r--r-- | RhSolutions.ExcelExtensions/Columns.cs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/RhSolutions.ExcelExtensions/Columns.cs b/RhSolutions.ExcelExtensions/Columns.cs index 1fbc0ef..014b755 100644 --- a/RhSolutions.ExcelExtensions/Columns.cs +++ b/RhSolutions.ExcelExtensions/Columns.cs @@ -4,35 +4,45 @@ namespace RhSolutions.ExcelExtensions; public class Columns : IEnumerable<Column> { - public Range Range { get; } public Table ParentTable { get; } public int Length { - get => Range.Columns.Count; + get => _range.Columns.Count; } + private Column[] _columns; + private Range _range; - public Columns(Range range, Table parentTable) + public Columns(Table parentTable) { - Range = range; ParentTable = parentTable; + _range = parentTable.Range; + _columns = new Column[Length]; } public Column this[int index] { get { - if (index < 0 || index + 1 > Range.Columns.Count) + if (index < 0 || index >= Length) { throw new IndexOutOfRangeException(); } - return new Column(Range.Columns[index + 1], ParentTable); + if (_columns[index] == null) + { + _columns[index] = new Column(_range.Columns[index + 1], ParentTable); + return _columns[index]; + } + else + { + return _columns[index]; + } } } public IEnumerator<Column> GetEnumerator() { - return new ColumnsEnumerator(Range, ParentTable); + return new ColumnsEnumerator(this); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); |