Click or drag to resize
CalculationWorks Logo
Creating Function Classes

This topic contains the following sections:

Simple Function

The example shows a simple function.

The BcfMandatoryAttribute will cause BCF Editor to show an error if the property is not used as parameter.

public class StringLengthFunction : BcfFunctionBase<int> {

    [BcfMandatory]
    public string StringValue { get; set; }

    public override int Compute() { return StringValue == null ? 0 : StringValue.Length; }
}
Tip Tip

Use code snipped {BCFF} from http://calculationworks.com/download

Generic Function

The example shows a function usable for all column data types. BCF Editor will use the column data type as generic type parameter T.

public class BooleanSwitchFunction<T> : BcfFunctionBase<T> {

    [BcfMandatory]
    public bool Switch { get; set; }

    [BcfMandatory]
    public T TrueValue { get; set; }

    [BcfMandatory]
    public T FalseValue { get; set; }

    public override T Compute() { return Switch ? TrueValue : FalseValue; }
}
See Also