Skip to main content

FunctionOperator Class

A function operator based on a FunctionOperatorType.

Namespace: DevExpress.Data.Filtering

Assembly: DevExpress.Data.v24.2.dll

NuGet Package: DevExpress.Data

Declaration

public class FunctionOperator :
    CriteriaOperator

The following members return FunctionOperator objects:

Remarks

The FunctionOperator class is a function operator that can be used along with other operators when constructing complex filter criteria. To create a function operator, create an instance of the FunctionOperator class and initialize its settings via the constructor parameters. See the FunctionOperatorType topic, for a list of the available function types.

In addition to built-in functions, you can implement and use any number of custom functions. Refer to How to: Implement a Custom Criteria Language Function Operator to learn more.

It’s also possible to use the CriteriaOperator.Parse method to create a CriteriaOperator operator for a specific expression.

Tip

Refer to the Build Criteria - Cheat Sheet article for more examples.

Example

The following example shows how to use the IIF function operator to construct filter criteria. The criteria is then used to select appropriate records from storage using an XPCollection. The criteria that are implemented are defined by the following expression: IIF(Field1 == 100, Field1, Field2) > 1000. Firstly the IIF(…) subexpression is evaluated. The result is then compared with 1000. Objects are selected by the criteria if the result of the IIF(…) function is greater than 1000 for them.

This example shows two equivalent ways to set up the filter criteria:

You can see that the second approach is easier and more human readable

Note

The CriteriaOperator.Parse method analyzes the string passed as a parameter, and then creates an equivalent tree of CriteriaOperator operators for it.

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

// Approach 1
// Define the operands for the IIF function operator.
CriteriaOperator[] operands = new CriteriaOperator[] {
   new BinaryOperator("Field1", 100),
   new OperandProperty("Field1"),
   new OperandProperty("Field2")
   };
CriteriaOperator criteria = new BinaryOperator(
   new FunctionOperator(FunctionOperatorType.Iif, operands),
   new OperandValue(1000),
   BinaryOperatorType.Greater
   );
XPCollection collection = new XPCollection(typeof(MyObject), criteria);

//Approach 2
CriteriaOperator criteria1 = CriteriaOperator.Parse(
  "Iif(Field1 == 100, Field1, Field2) > 1000");
XPCollection collection1 = new XPCollection(typeof(MyObject), criteria1);

Inheritance

Object
CriteriaOperator
FunctionOperator
See Also