A newer version of this page is available. Switch to the current version.

Implementing Custom Functions

  • 2 minutes to read

This document explains how you can implement custom functions for CriteriaOperator-based criteria used in filter conditions and expressions supported in many DevExpress products (including grids, pivot grids, Reporting, etc.) in addition to built-in functions (see Criteria Language Syntax and FunctionOperatorType).

NOTE

Custom functions are not available in the visual tree of Filter Controls (FilterControl and FilterEditorControl).

Declaring Custom Functions

A custom function is a class implementing the following interfaces.

The ICustomFunctionOperatorFormattable and ICustomFunctionOperatorBrowsable interfaces inherit from the ICustomFunctionOperator interface, and extend it with a specific advanced functionality. Thus, you can implement ICustomFunctionOperatorFormattable or ICustomFunctionOperatorBrowsable (or both of them, depending on the capabilities you want to offer with your custom function) and as a result provide an ICustomFunctionOperator implementation.

Refer to the How to: Implement a Custom Criteria Language Function Operator for a sample ICustomFunctionOperatorFormattable interface implementation (a custom function that returns the month of a date).

Registering Custom Functions

Once a custom function is declared, you can register it in your application using any of the following methods.

  • Pass a custom function to CriteriaOperator.RegisterCustomFunction or CriteriaOperator.RegisterCustomFunctions.

    These static methods significantly simplify the registration process. With a single method call, you make custom functions available wherever CriteriaOperator-based criteria are processed - whether it is an expression or a database query built with XPO.

  • Pass a custom function to a data store provider's RegisterCustomFunctionOperator method and add it to a dictionary's XPDictionary.CustomFunctionOperators collection.

    This is an outdated registration technique, which exposes the custom function only to XPO queries based on dictionary entries.

To unregister a custom function, call the CriteriaOperator.UnregisterCustomFunction method.

To see a code example on implementing custom functions, refer to the How to: Implement a Custom Criteria Language Function Operator topic in the XPO documentation.

To learn how to implement custom functions and criteria, and use them in LINQ expressions built with XPO, see How to: Implement Custom Functions and Criteria in LINQ to XPO.