public TreeTable DeepCloneWithTableColumns(TableColumns tableColumns) { var result = new TreeTable( tableColumns, this.TableRows?.DeepClone(), this.Format?.DeepClone()); return(result); }
public TreeTable( TableColumns tableColumns, TableRows tableRows = null, TableFormat format = null) { if (tableColumns == null) { throw new ArgumentNullException(nameof(tableColumns)); } var numberOfColumns = tableColumns.Columns.Count; var ids = new List <string>(); ids.AddRange(tableColumns.Columns.Where(_ => !string.IsNullOrWhiteSpace(_.Id)).Select(_ => _.Id)); var allRowsInOrder = tableRows == null ? new List <RowBase>() : tableRows.GetAllRowsInOrder(); if (allRowsInOrder.Any(_ => _.GetNumberOfColumnsSpanned() != numberOfColumns)) { throw new ArgumentException(Invariant($"{nameof(tableRows)} contains a row or descendant row that does not span all {numberOfColumns} of the defined columns.")); } ids.AddRange(allRowsInOrder.Where(_ => !string.IsNullOrWhiteSpace(_.Id)).Select(_ => _.Id)); var allCells = tableRows == null ? new List <ICell>() : tableRows.GetAllCells(); var allCellsWithIds = allCells.Where(_ => !string.IsNullOrWhiteSpace(_.Id)).ToList(); ids.AddRange(allCellsWithIds.Select(_ => _.Id)); if (ids.Distinct().Count() != ids.Count) { throw new ArgumentException(Invariant($"Two or more elements (i.e. columns, rows, cells) have the same identifier.")); } if (allCells.Distinct(new ReferenceEqualityComparer <ICell>()).Count() != allCells.Count) { throw new ArgumentException(Invariant($"One or more {nameof(ICell)} objects are used multiple times in the tree table.")); } this.TableColumns = tableColumns; this.TableRows = tableRows; this.Format = format; }