Formatters |
[This is preliminary documentation and is subject to change.]
Formatters are used to replace the value when setting a cell-value. For example trim strings, truncate over-sized strings or round decimals. If a column has a formatter all values that are applied will pass the formatter, also default and computed values.
You can define a formatter in BCF-Editor/Columns/Formatter or in code:Formatter.
Define a formatter in BCF-EditorTo trim strings enter in Column/Format: (column, value) => value?.Trim().
Define formatters in codepublic static class SetupHelper { public static void AddStringTrimming(BcfDataSetSetup setup) { foreach(var stringColumnSetup in setup.Tables.Where(t => t.Columns != null).SelectMany(t => t.Columns).OfType<BcfColumnSetup<string>>()) { if(!stringColumnSetup.HasFormatter) stringColumnSetup.Formatter = StringColumnFormatter; } } private static string StringColumnFormatter(BcfColumn<string> column, string proposedValue) { var s = proposedValue?.Trim(); if(column.AllowNull && s == string.Empty) return null; return s; } }