Пример #1
0
        private string Format(object o, ColumnDisplaySettings formattingOptions)
        {
            if (o == null)
            {
                return(null);
            }

            switch (formattingOptions)
            {
            case StringDisplaySettings stringOptions:
                switch (stringOptions.Case)
                {
                case StringCase.Unchanged:
                    return(o.ToString());

                case StringCase.AllCaps:
                    return(o.ToString().ToUpper());

                case StringCase.AllLowercase:
                    return(o.ToString().ToLower());

                default:
                    throw new InvalidEnumArgumentException();
                }

            case NumericDisplaySettings numericOptions:
                return(((double)o).ToStringWithTrailingZeros(numericOptions.DecimalPrecision));

            default:
                throw new InvalidDataException(
                          $"did not expect formatting options of type {formattingOptions.GetType()} for object of type {o.GetType()}");
            }
        }
Пример #2
0
        public void SetColumnNumericDisplayPrecision(string columnName, int decimalPrecision)
        {
            ColumnDisplaySettings formatting = GetFormattingAtColumn(columnName);

            if (formatting is NumericDisplaySettings settings)
            {
                settings.DecimalPrecision = decimalPrecision;
                return;
            }

            throw new ArgumentException("cannot set decimal precision for non-numeric column data");
        }
Пример #3
0
        public void SetColumnTextCapitalization(string columnName, StringCase stringCase)
        {
            ColumnDisplaySettings formatting = GetFormattingAtColumn(columnName);

            if (formatting is StringDisplaySettings settings)
            {
                settings.Case = stringCase;
                return;
            }

            throw new ArgumentException("cannot set case for non-string column data");
        }
Пример #4
0
        public void SetColumnAlignment(string columnName, Alignment alignment)
        {
            ColumnDisplaySettings formatting = GetFormattingAtColumn(columnName);

            formatting.Alignment = alignment;
        }