Table log Entry was added
This commit is contained in:
10
StructureHelperCommon/Models/Tables/IShTableRow.cs
Normal file
10
StructureHelperCommon/Models/Tables/IShTableRow.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public interface IShTableRow<T>
|
||||
{
|
||||
List<T> Elements { get; }
|
||||
int RowSize { get; }
|
||||
}
|
||||
}
|
||||
77
StructureHelperCommon/Models/Tables/ListTable.cs
Normal file
77
StructureHelperCommon/Models/Tables/ListTable.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public class ListTable<T>
|
||||
{
|
||||
private List<IShTableRow<T>> table;
|
||||
|
||||
public int RowSize { get; }
|
||||
|
||||
public ListTable(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
|
||||
RowSize = rowSize;
|
||||
table = new List<IShTableRow<T>>();
|
||||
}
|
||||
|
||||
// Add a new row to the table
|
||||
public void AddRow(IShTableRow<T> tableRow)
|
||||
{
|
||||
table.Add(tableRow);
|
||||
}
|
||||
public void AddRow()
|
||||
{
|
||||
table.Add(new ShTableRow<T>(RowSize));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all rows in the table
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<IShTableRow<T>> GetAllRows()
|
||||
{
|
||||
return table;
|
||||
}
|
||||
|
||||
public List<T> GetElementsFromRow(int rowIndex)
|
||||
{
|
||||
if (rowIndex >= 0 && rowIndex < table.Count)
|
||||
{
|
||||
return table[rowIndex].Elements;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IndexOutOfRangeException("Row index is out of range.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a value at the specified column and row index
|
||||
/// </summary>
|
||||
/// <param name="columnIndex"></param>
|
||||
/// <param name="rowIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public void SetValue(int columnIndex, int rowIndex, T value)
|
||||
{
|
||||
if (columnIndex >= 0 && columnIndex < RowSize &&
|
||||
rowIndex >= 0 && rowIndex < table.Count)
|
||||
{
|
||||
table[rowIndex].Elements[columnIndex] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IndexOutOfRangeException("Column or row index is out of range.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
StructureHelperCommon/Models/Tables/ShTableRow.cs
Normal file
38
StructureHelperCommon/Models/Tables/ShTableRow.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Tables
|
||||
{
|
||||
public class ShTableRow<T> : IShTableRow<T>
|
||||
{
|
||||
private List<T> elements;
|
||||
|
||||
public int RowSize { get; }
|
||||
|
||||
public ShTableRow(int rowSize)
|
||||
{
|
||||
if (rowSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("Row size must be greater than 0.", nameof(rowSize));
|
||||
}
|
||||
|
||||
RowSize = rowSize;
|
||||
elements = new List<T>(rowSize);
|
||||
for (int i = 0; i < rowSize; i++)
|
||||
{
|
||||
elements.Add(default);
|
||||
}
|
||||
}
|
||||
|
||||
// Property to access elements in the row
|
||||
public List<T> Elements => elements;
|
||||
|
||||
internal void Add(object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user