Click or drag to resize

Formatters

This topic contains the following sections:

Formatter

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-Editor

To trim strings enter in Column/Format: (column, value) => value?.Trim().

Define formatters in code
Add Trimming to all String Columns
public 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;
    }
}
See Also