I wrote the following custom aggregate function to concatenate the expression results of a databand:
Code: Select all
/// <summary>
/// Concats the expression by using a delimiter.
/// </summary>
public class ConcatFunctionService : StiAggregateFunctionService
{
private string _summary = String.Empty;
private string _delimiter = ", ";
/// <summary>
/// Gets value, indicates that this function require a parameter.
/// </summary>
public override bool RecureParam
{
get
{
return true;
}
}
/// <summary>
/// Gets a service name.
/// </summary>
public override string ServiceName
{
get
{
return "Concat";
}
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="runningTotal">true to running total.</param>
public ConcatFunctionService(bool runningTotal)
: base(runningTotal)
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="runningTotal">true to running total.</param>
/// <param name="delimiter">Delimiter.</param>
public ConcatFunctionService(bool runningTotal, string delimiter)
: base(runningTotal)
{
_delimiter = delimiter;
}
/// <summary>
/// Default constructor.
/// </summary>
public ConcatFunctionService()
{
}
/// <summary>
/// A value calculation.
/// </summary>
/// <param name="value">Value.</param>
public override void CalcItem(object value)
{
if (value == null || value == DBNull.Value)
{
return;
}
if (!String.IsNullOrEmpty(this._summary)) this._summary += this._delimiter;
this._summary = this._summary + Convert.ToString(value);
}
/// <summary>
/// Returns the type of the result.
/// </summary>
public override Type GetResultType()
{
return typeof(string);
}
/// <summary>
/// Returns the calculation result.
/// </summary>
/// <returns>Calculation result.</returns>
public override object GetValue()
{
return this._summary;
}
/// <summary>
/// First initialization.
/// </summary>
public override void Init()
{
if (!base.RunningTotal || this.IsFirstInit)
{
this._summary = String.Empty;
}
}
/// <summary>
/// Restores the earlier saved object state.
/// </summary>
/// <param name="stateName">A name of the state being restored.</param>
public override void RestoreState(string stateName)
{
if (base.States.IsExist(stateName, this))
{
this._summary = Convert.ToString(base.States.Pop(stateName, this, "summary"));
}
}
/// <summary>
/// Saves the current state of an object.
/// </summary>
/// <param name="stateName">A name of the state being saved.</param>
public override void SaveState(string stateName)
{
base.States.Push(stateName, this, "summary", this._summary);
}
/// <summary>
/// Sets the calculation result.
/// </summary>
public override void SetValue(object value)
{
this._summary = Convert.ToString(value);
}
}
Code: Select all
StiOptions.Services.AggregateFunctions.Add(new ConcatFunctionService());
If I specify the additional delimiter parameter, the Concat aggregate function no longer works

Working:
Code: Select all
{Concat(DataAddress,Address.FirstName)}
Code: Select all
{Concat(DataAddress,Address.FirstName,false,"-")}
Thank you very much for your support in advance,
Kind regards,
Markus