ICustomAggregateFunction Interface
Declares the base functionality for custom aggregate functions.
Namespace: DevExpress.DataProcessing.Criteria
Assembly:
DevExpress.PivotGrid.v24.1.Core.dll
NuGet Packages:
DevExpress.PivotGrid.Core, DevExpress.Win.Navigation
Declaration
public interface ICustomAggregateFunction :
ICustomFunctionOperator
Public Interface ICustomAggregateFunction
Inherits ICustomFunctionOperator
The following code snippets show how to implement a custom function that uses string concatenation to aggregate data in client mode.
using DevExpress.Data.Filtering;
using DevExpress.DataAccess.ExpressionEditor;
using DevExpress.DataProcessing.Criteria;
using System;
using System.Collections.Generic;
namespace Dashboard_StringConcatAggregate {
class StringConcatFunction : ICustomAggregateFunction, ICustomFunctionOperatorBrowsable,
ICustomFunctionCategory {
public string Name => "StringConcat";
public int MinOperandCount => 1;
public int MaxOperandCount => 1;
public string Description => @"Takes strings, aggregates by input value,
and displays them separated by commas.";
public FunctionCategory Category => DevExpress.Data.Filtering.FunctionCategory.Text;
public string FunctionCategory => "Aggregate";
public object Evaluate(params object[] operands) {
throw new NotImplementedException();
}
public Type GetAggregationContextType(Type inputType) {
return typeof(StringConcatState);
}
public bool IsValidOperandCount(int count) {
return count <= MaxOperandCount && count >= MinOperandCount;
}
public bool IsValidOperandType(int operandIndex, int operandCount, Type type) {
return IsValidOperandCount(operandCount) && operandIndex == 0 && type == typeof(string);
}
public Type ResultType(params Type[] operands) {
return typeof(string);
}
}
class StringConcatState : ICustomAggregateFunctionContext<string, string> {
List<string> enumeration = new List<string>();
ISet<string> names = new HashSet<string>();
public string GetResult() {
return String.Join(", ", enumeration.ToArray());
}
public void Process(string value) {
if (names.Add(value)) {
enumeration.Add(value);
}
}
}
}
Imports DevExpress.Data.Filtering
Imports DevExpress.DataAccess.ExpressionEditor
Imports DevExpress.DataProcessing.Criteria
Namespace Dashboard_StringConcatAggregate
Friend Class StringConcatFunction
Implements ICustomAggregateFunction, ICustomFunctionOperatorBrowsable,
ICustomFunctionCategory
Public ReadOnly Property Name() As String Implements DevExpress.Data.Filtering.ICustomFunctionOperator.Name
Get
Return "StringConcat"
End Get
End Property
Public ReadOnly Property MinOperandCount() As Integer Implements ICustomFunctionOperatorBrowsable.MinOperandCount
Get
Return 1
End Get
End Property
Public ReadOnly Property MaxOperandCount() As Integer Implements ICustomFunctionOperatorBrowsable.MaxOperandCount
Get
Return 1
End Get
End Property
Public ReadOnly Property Description() As String Implements ICustomFunctionOperatorBrowsable.Description
Get
Return "Takes strings, aggregates by input value, and displays them separated by commas."
End Get
End Property
Public ReadOnly Property Category() As FunctionCategory Implements ICustomFunctionOperatorBrowsable.Category
Get
Return DevExpress.Data.Filtering.FunctionCategory.Text
End Get
End Property
Private ReadOnly Property ICustomFunctionCategory_FunctionCategory As String Implements ICustomFunctionCategory.FunctionCategory
Get
Return "Aggregate"
End Get
End Property
Public Function Evaluate(ParamArray ByVal operands() As Object) As Object Implements DevExpress.Data.Filtering.ICustomFunctionOperator.Evaluate
Throw New NotImplementedException()
End Function
Public Function IsValidOperandCount(ByVal count As Integer) As Boolean Implements ICustomFunctionOperatorBrowsable.IsValidOperandCount
Return count <= MaxOperandCount AndAlso count >= MinOperandCount
End Function
Public Function IsValidOperandType(ByVal operandIndex As Integer, ByVal operandCount As Integer, ByVal type As Type) As Boolean Implements ICustomFunctionOperatorBrowsable.IsValidOperandType
Return IsValidOperandCount(operandCount) AndAlso operandIndex = 0 AndAlso type Is GetType(String)
End Function
Public Function ResultType(ParamArray ByVal operands() As Type) As Type Implements DevExpress.Data.Filtering.ICustomFunctionOperator.ResultType
Return GetType(String)
End Function
Private Function GetAggregationContextType(inputType As Type) As Type Implements ICustomAggregateFunction.GetAggregationContextType
Return GetType(StringConcatState)
End Function
End Class
Friend Class StringConcatState
Implements ICustomAggregateFunctionContext(Of String, String)
Private enumeration As New List(Of String)()
Private names As ISet(Of String) = New HashSet(Of String)()
Public Function GetResult() As String Implements ICustomAggregateFunctionContext(Of String, String).GetResult
Return String.Join(", ", enumeration.ToArray())
End Function
Public Sub Process(ByVal value As String) Implements ICustomAggregateFunctionContext(Of String, String).Process
If names.Add(value) Then
enumeration.Add(value)
End If
End Sub
End Class
End Namespace
See Also