Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. namespace TableNet
  2. {
  3. public class Table
  4. {
  5.  
  6. private readonly Cell[,] _cells;
  7.  
  8. public Cell this[int i, int j]
  9. {
  10. get => _cells[i, j];
  11. set
  12. {
  13. if(value != null)
  14. _cells[i, j] = value;
  15. else throw new ArgumentNullException();
  16. }
  17. }
  18.  
  19. public ReadOnlyCollection<Row> Rows { get; }
  20. public ReadOnlyCollection<Column> Columns { get; }
  21.  
  22.  
  23. public Table(int rows, int columns)
  24. {
  25. _cells = new Cell[rows, columns];
  26.  
  27. for (var i = 0; i < rows; i++)
  28. {
  29. for (var j = 0; j < columns; j++)
  30. {
  31. _cells[i, j] = new Cell();
  32. }
  33. }
  34. Rows = CreateRows(rows, columns, Row.DEFAULT_ROW_HEIGHT);
  35. Columns = CreateColumns(rows, columns, Column.DEFAULT_COLUMN_WIDTH);
  36. }
  37.  
  38. public ReadOnlyCollection<Row> CreateRows(int rows, int columns, int height)
  39. {
  40. Row[] r = new Row[rows];
  41. for (var i = 0; i < rows; i++)
  42. {
  43. r[i] = new Row(this, i, columns, height);
  44. }
  45. return Array.AsReadOnly(r);
  46. }
  47.  
  48. private ReadOnlyCollection<Column> CreateColumns(int rows, int columns, int width)
  49. {
  50. Column[] r = new Column[columns];
  51. for (var i = 0; i < columns; i++)
  52. {
  53. r[i] = new Column(this, i, rows, width);
  54. }
  55. return Array.AsReadOnly(r);
  56. }
  57. }
  58. }
  59.  
  60. namespace TableNet
  61. {
  62. public class Row
  63. {
  64. public const int DEFAULT_ROW_HEIGHT = 3;
  65.  
  66.  
  67. public int Height
  68. {
  69. get => Height;
  70. set => Height = Math.Max(0, value);
  71. }
  72.  
  73. public int Columns { get; }
  74.  
  75. private readonly Table _table;
  76.  
  77. private readonly int _rowIndex;
  78.  
  79. //public char Filler { set => Cells.ForEach(c => c.Filler = value); }
  80.  
  81. internal Row(Table table, int rowIndex, int columns, int height)
  82. {
  83. _table = table;
  84. _rowIndex = rowIndex;
  85. Columns = columns;
  86. Height = height;
  87. }
  88.  
  89. public Cell this[int column]
  90. {
  91. get => _table[_rowIndex, column];
  92. set => _table[_rowIndex, column] = value;
  93. }
  94. }
  95.  
  96. }
Add Comment
Please, Sign In to add comment