Skip to main content

ICustomFunctionOperatorFormattable Interface

Defines server-side processing for custom functions.

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v22.1.dll

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.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ICustomFunctionOperatorFormattable interface.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also