Example E3396
Visible to All Users

How to delete all criteria corresponding to a particular field from CriteriaOperator

This example demonstrates how to implement a helper that removes all expressions referencing a certain property from the CriteriaOperator. For example, you may want to programmatically remove fragments like "[SavedPassword] = '***'" from filter expressions that persist on client computers, because you decided to remove the SavedPassword property from the model for security reasons.

Although this task can be accomplished using regular expressions, this approach is too complicated and is applicable only to CriteriaOperator expressions that follow a certain pattern. This example uses a different technique, which allows you to support expressions of any complexity with minimum effort.

The solution demonstrated in this example uses the concept described in this Knowledge Base article: Implementation of the base class for a CriteriaOperator expression patcher. The DevExpress.Data.Filtering.Helpers.ClientCriteriaLazyPatcherBase.AggragatesCommonProcessingBase class is used in this example as a base class for the CriteriaPatcherSkipProperties class (in version 17.2 and earlier use the CriteriaPatcherBase class implemented in the example).

To remove any reference to a specific property from the CriteriaOperator expression, override the CriteriaPatcherBase.VisitProperty method, and return null (Nothing in Visual Basic) if the property name matches the name of a property that should be removed.

C#
protected override CriteriaOperator VisitProperty(OperandProperty theOperand) { if(PropertiesToremove.Contains(theOperand.PropertyName)) return null; return theOperand; }
Visual Basic
Protected Overrides Function VisitProperty(ByVal theOperand As OperandProperty) As CriteriaOperator If PropertiesToremove.Contains(theOperand.PropertyName) Then Return Nothing End If Return theOperand End Function

However, this is incomplete. The expression will contain invalid statements if you simply remove properties from it: "() = #2015-12-30# And StartsWith([City], 'q')" . To delete invalid statements from the expression, override the VisitAggregate, VisitFunction, VisitGroup, VisitIn, VisitUnary, VisitBinary, and VisitBetween methods. The implementation of overridden methods is demonstrated in the CriteriaPatcherSkipProperties.cs and CriteriaPatcherSkipProperties.vb files.

See also:
Implementation of the base class for a CriteriaOperator expression patcher

How to create a custom converter to convert the CriteriaOperator to the System.String type

Description

Replaced CriteriaPatcherBase with ClientCriteriaLazyPatcherBase.

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.