/// <summary>
        /// Gets all of the rows, header and descendants included, in the order they appear in the table.
        /// </summary>
        /// <param name="tableRows">The table rows.</param>
        /// <returns>
        /// The rows, header and descendants included, in the order they appear in the table.
        /// </returns>
        public static IReadOnlyList <RowBase> GetAllRowsInOrder(
            this TableRows tableRows)
        {
            if (tableRows == null)
            {
                throw new ArgumentNullException(nameof(tableRows));
            }

            var result = new List <RowBase>();

            if (tableRows.HeaderRows != null)
            {
                result.AddRange(tableRows.HeaderRows.Rows);
            }

            if (tableRows.DataRows != null)
            {
                result.AddRange(GetAllDataRowsInOrder(tableRows.DataRows.Rows));
            }

            if (tableRows.FooterRows != null)
            {
                result.AddRange(tableRows.FooterRows.Rows);
            }

            return(result);
        }
        public TreeTable DeepCloneWithTableRows(TableRows tableRows)
        {
            var result = new TreeTable(
                this.TableColumns?.DeepClone(),
                tableRows,
                this.Format?.DeepClone());

            return(result);
        }
コード例 #3
0
        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;
        }
        /// <summary>
        /// Gets all cells in a table.
        /// </summary>
        /// <param name="tableRows">The table rows.</param>
        /// <returns>
        /// All cells in a table.
        /// </returns>
        public static IReadOnlyCollection <ICell> GetAllCells(
            this TableRows tableRows)
        {
            if (tableRows == null)
            {
                throw new ArgumentNullException(nameof(tableRows));
            }

            var allRowsInOrder = tableRows.GetAllRowsInOrder();

            var result = new List <ICell>(allRowsInOrder.SelectMany(_ => _.Cells));

            var slottedCells = result.OfType <ISlottedCell>().SelectMany(_ => _.SlotIdToCellMap.Values).ToList();

            result.AddRange(slottedCells);

            return(result);
        }