In version 18.1 we introduced helper classes that can be used to traverse through and modify or copy CriteriaOperator objects. These classes are designed to be extended using inheritance.
Please note that this answer describes internal and undocumented API, and we cannot guarantee that it will not be changed in the future.
CriteriaOperator descendants represent a filter expression in a tree-like data structure, where each node is another CriteriaOperator. If a filter expression is provided as a string, use the CriteriaOperator.Parse method to convert a string expression into a CriteriaOperator instance.
Each helper class has a separate virtual Visit method to process all CriteriaOperator descendants. When processing the CriteriaOperator object, the helper class recursively calls corresponding Visit methods on each node and builds a new expression tree by substituting original nodes with nodes returned by its Visit methods.
The list of virtual Visit methods is provided at the end of this article. To modify the filter expression, override a certain Visit method and return a new CriteriaOperator instance. Take into account the following information when considering which helper class is preferable for a specific task.
Methods in the DevExpress.Data.Filtering.Helpers.ClientCriteriaLazyPatcherBase class process child nodes of the CriteriaOperator instance passed as a parameter by calling corresponding Visit methods and comparing each result with the corresponding original node. If all results equal the corresponding original node, the Visit method returns the original CriteriaOperator object passed as a parameter. Otherwise, it creates a new CriteriaOperator descendant based on the processed nodes of the original CriteriaOperator object.
Methods in the DevExpress.Data.Filtering.Helpers.ClientCriteriaClonerBase class always create a new CriteriaOperator descendant based on the processed nodes of the original CriteriaOperator.
The ClientCriteriaLazyPatcherBase class does not implement the Visit(AggregateOperand) and Visit(JoinOperand) methods. Depending on a specific scenario, it is possible to:
- throw the System.NotImplemented exception if there is no need to support these operators.
- inherit from the nested ClientCriteriaLazyPatcherBase.AggregatesAsIsBase class. In this class, corresponding Visit methods return the AggregateOperand or JoinOperand object passed as a parameter without processing child nodes.
- inherit from the nested ClientCriteriaLazyPatcherBase.AggregatesCommonProcessingBase class. In this class, corresponding Visit methods process the AggregateOperand and JoinOperand in the same manner as other operands.
- implement the Visit(AggregateOperand) and Visit(JoinOperand) methods manually.
The ClientCriteriaClonerBase class does not implement the Visit(OperandValue) method. Depending on a specific scenario, it is possible to:
- implement the Visit(OperandValue) method manually.
- inherit from the nested ClientCriteriaClonerBase.DeepValuesCloneBase class. Its Visit(OperandValue) method gets the OperandProperty.Value property value and creates its clone if the value is an ICloneable interface implementor.
- inherit from the nested ClientCriteriaClonerBase.NoValuesCloneBase class. This class creates a new OperandValue instance using the original operand's value.
The following virtual methods are provided by helper classes:
CriteriaOperator Visit(AggregateOperand)
CriteriaOperator Visit(OperandProperty)
CriteriaOperator Visit(JoinOperand)
CriteriaOperator Visit(BetweenOperator)
CriteriaOperator Visit(BinaryOperator)
CriteriaOperator Visit(UnaryOperator)
CriteriaOperator Visit(InOperator)
CriteriaOperator Visit(GroupOperator)
CriteriaOperator Visit(OperandValue)
CriteriaOperator Visit(FunctionOperator)
Refer to the following examples to learn more:
How to delete all criteria corresponding to a particular field from CriteriaOperator
How to make the auto filter row's filter accent insensitive
In version 17.2 and earlier, you can use helper classes from the attached files.