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()}"); } }
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"); }
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"); }
public void SetColumnAlignment(string columnName, Alignment alignment) { ColumnDisplaySettings formatting = GetFormattingAtColumn(columnName); formatting.Alignment = alignment; }