Ejemplo n.º 1
0
        private static RowBase PadInternal(
            this RowBase row,
            int requiredNumberOfColumnsSpanned)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            if (requiredNumberOfColumnsSpanned <= 0)
            {
                throw new ArgumentOutOfRangeException(Invariant($"{nameof(requiredNumberOfColumnsSpanned)} must be > 0; provided value: {requiredNumberOfColumnsSpanned}."));
            }

            RowBase result;

            var currentNumberOfColumnsSpanned = row.GetNumberOfColumnsSpanned();

            if (currentNumberOfColumnsSpanned >= requiredNumberOfColumnsSpanned)
            {
                result = row;
            }
            else
            {
                var additionalColumnsSpanned = requiredNumberOfColumnsSpanned - currentNumberOfColumnsSpanned;

                var newCells = row.Cells.ToList();

                newCells.AddRange(Enumerable.Range(0, additionalColumnsSpanned).Select(_ => new NullCell()));

                result = row.DeepCloneWithCells(newCells);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the number of columns spanned by a row.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns>
        /// The number of columns spanned the row.
        /// </returns>
        public static int GetNumberOfColumnsSpanned(
            this RowBase row)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            var result = row
                         .Cells
                         .Select(_ => _.ColumnsSpanned ?? 1)
                         .Sum();

            return(result);
        }