Skip to main content
A newer version of this page is available. .

ICustomFunctionOperatorFormattable Interface

Defines server-side processing for custom functions.

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v20.2.dll

NuGet Packages: DevExpress.Data, DevExpress.WindowsDesktop.Data

Declaration

public interface ICustomFunctionOperatorFormattable :
    ICustomFunctionOperator

The following members return ICustomFunctionOperatorFormattable objects:

Remarks

Implement this interface in addition to the ICustomFunctionOperator interface to provide a database-specific SQL command for your custom function. This interface declares the functionality required to evaluate the custom function within criteria on the database server.

public class SampleCustomOperatorFormattable : ICustomFunctionOperatorFormattable {
    public string Name => "CalcCost";
    public object Evaluate(params object[] operands) {
        return ((decimal)operands[0] * (int)operands[1]);
    }
    public string Format(Type providerType, params string[] operands) {
        if(typeof(PostgreSqlConnectionProvider).IsAssignableFrom(providerType)) {
            return $" {operands[0]} * {operands[1]} ";
        } else throw new NotSupportedException();
    }
    public Type ResultType(params Type[] operands) {
        return typeof(decimal);
    }
    public static SampleCustomOperatorFormattable Instance = new SampleCustomOperatorFormattable();
    public static void Register() {
        CriteriaOperator.RegisterCustomFunction(Instance);
    }
    public static void Unregister() {
        CriteriaOperator.UnregisterCustomFunction(Instance);
    }
}

If you want to make your custom function available to end users in Expression Editors, implement the ICustomFunctionOperatorBrowsable interface as well.

See Also