/
InToAggregatePatcher.vb
32 lines (25 loc) · 1.42 KB
/
InToAggregatePatcher.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Imports DevExpress.Data.Filtering
Imports DevExpress.Data.Filtering.Helpers
Imports System.Linq
Namespace FilterDropDown_AgregateOperators.Behaviors
Public Class InToAggregatePatcher
Inherits ClientCriteriaLazyPatcherBase.AggregatesCommonProcessingBase
Public Shared FieldName As String
Public Shared DataItemId As String
Public Shared Function Patch(ByVal source As CriteriaOperator) As CriteriaOperator
Return New InToAggregatePatcher().Process(source)
End Function
Public Overrides Function Visit(ByVal theOperator As InOperator) As CriteriaOperator
Dim result = CType(MyBase.Visit(theOperator), InOperator)
Dim [property] = TryCast(result.LeftOperand, OperandProperty)
If Equals([property]?.PropertyName, FieldName) AndAlso result.Operands.All(Function(c) TypeOf c Is OperandValue) Then
Dim items = result.Operands.Cast(Of OperandValue)().[Select](Function(c) c.Value)
Dim ItemValues = items.[Select](Function(item) New OperandValue(item.GetType().GetProperty(DataItemId).GetValue(item)))
Dim inOperator = New InOperator(New OperandProperty(DataItemId), ItemValues)
Dim newOperator = CriteriaOperator.Parse(FieldName & "[" & inOperator.ToString() & "]")
Return newOperator
End If
Return result
End Function
End Class
End Namespace