using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StructureHelperCommon.Models.Tables { public class ShTable { private List> table; public int RowSize { get; } public ShTable(int rowSize) { if (rowSize <= 0) { throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize)); } RowSize = rowSize; table = new List>(); } // Add a new row to the table public void AddRow(IShTableRow tableRow) { table.Add(tableRow); } public void AddRow() { table.Add(new ShTableRow(RowSize)); } /// /// Get all rows in the table /// /// public List> GetAllRows() { return table; } public List> GetElementsFromRow(int rowIndex) { if (rowIndex >= 0 && rowIndex < table.Count) { return table[rowIndex].Elements; } else { throw new IndexOutOfRangeException("Row index is out of range."); } } public int RowCount => GetAllRows().Count(); public IShTableCell GetCell(int rowIndex, int columnIndex) { var row = GetElementsFromRow(rowIndex); var cell = row[columnIndex]; return cell; } /// /// Set a value at the specified column and row index /// /// /// /// /// public void SetValue(int columnIndex, int rowIndex, T value) { if (columnIndex >= 0 && columnIndex < RowSize && rowIndex >= 0 && rowIndex < table.Count) { table[rowIndex].Elements[columnIndex].Value = value; } else { throw new IndexOutOfRangeException("Column or row index is out of range."); } } } }