Exemple #1
0
        public static T Sum <T>(this System.Data.DataTable dataTable, string range)
            where T : struct
        {
            ArgumentGuards.GuardAgainstNullDataTable(dataTable);
            ArgumentGuards.GuardAgainstNullRange(range);

            var rangeTuple = dataTable.TranslateRange(range);

            return(rangeTuple.HasValue ? Sum <T>(dataTable, rangeTuple.Value) : default(T));
        }
        public static string Shift(this System.Data.DataTable table, string range, string toColumn)
        {
            ArgumentGuards.GuardAgainstNullTable(table);
            ArgumentGuards.GuardAgainstNullRange(range);

            if (string.IsNullOrEmpty(toColumn))
            {
                throw new ArgumentNullException(nameof(toColumn));
            }

            var tuple = table.TranslateRange(range);

            if (!tuple.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(range), $"The data table does not contain the range {range}.");
            }

            if (!CellRange.IsSameColumn(tuple.Value))
            {
                throw new ArgumentException("A shift cannot be performed across multiple columns.", nameof(range));
            }

            return($"{toColumn}{tuple.Value.Item1.Row + 1}:{toColumn}{tuple.Value.Item2.Row + 1}");
        }
        public void It_should_throw_an_exception_for_a_null_range()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => _DataTable.TranslateRange(null));

            Assert.AreEqual($"Value cannot be null. (Parameter 'range')", exception.Message, exception.Message);
        }