Progress® Telerik® Reporting R3 2017

IAggregateFunction Interface

Provides custom (user-defined) implementation for aggregate function.

Namespace:  Telerik.Reporting.Expressions
Assembly:  Telerik.Reporting (in Telerik.Reporting.dll)

Syntax

public interface IAggregateFunction

The IAggregateFunction type exposes the following members.

Methods

  NameDescription
Public methodAccumulate
Accumulates the passed values in the aggregate.
Public methodGetValue
Gets the value that the aggregate instance keeps currently accumulated.
Public methodInit
Initializes the aggregate function instance. Implement to set the aggregate in its initial state ready to accumulate and merge values.
Public methodMerge
Merges another instance of the same aggregate function into the current instance. Implement this method to allow the reporting engine to merge the two resulting aggregates coming from two subsets of the aggregated data source rows.
Top

Remarks

Implement this interface to provide custom logic when aggregating values over a set of rows from the data source. Apply the AggregateFunctionAttribute class to the aggregate implementation in order to set the name and description of the aggregate function. If no AggregateFunctionAttribute is defined, the name of the aggregate function is the name of the actual type that implements the IAggregateFunction interface. The word "Aggregate" is trimmed from the type name if it ends with it.

Examples

This example shows how to implement user-defined aggregate.
[AggregateFunction(Description = "Concatenation aggregate. Output: (value1, value2, ...)", Name = "Concatenate")]
class ConcatenateAggregate : IAggregateFunction
{
    string result;

    public void Accumulate(object[] values)
    {
        // The aggregate function expects one parameter
        object value = values[0];

        // null values are not aggregated
        if (null == value)
        {
            return;
        }

        // The actual accumulation
        if (this.result.Length > 0)
        {
            result += ", ";
        }
        this.result += value.ToString();
    }

    public object GetValue()
    {
        return string.Format("({0})", this.result);
    }

    public void Init()
    {
        // Add aggregate function initialization code here if needed
        this.result = string.Empty;
    }

    public void Merge(IAggregateFunction aggregateFunction)
    {
        ConcatenateAggregate aggregate = (ConcatenateAggregate)aggregateFunction;

        if (aggregate.result.Length > 0)
        {
            if (this.result.Length > 0)
            {
                result += ", ";
            }
            this.result += aggregate.result;
        }
    }
}

See Also