Click or drag to resize

BcfFormatT Delegate

[This is preliminary documentation and is subject to change.]

Formats values before set in Value (e.g trim strings, round decimals).

Namespace:  CalculationWorks.BusinessModel
Assembly:  CalculationWorks.BusinessModel (in CalculationWorks.BusinessModel.dll) Version: 4.0.0-beta7
Syntax
public delegate T BcfFormat<T>(
	BcfColumn<T> column,
	T proposedValue
)

Parameters

column
Type: CalculationWorks.BusinessModelBcfColumnT
The column.
proposedValue
Type: T
The input value.

Type Parameters

T
The Value-property-type.

Return Value

Type: T
Examples
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