|
Namespace Aggregates
''' <summary>
''' An aggregate for string concatenation, equivalent to String.Join() method. Usage: Element Type="AggregateElement" DataSource="" Text="List of names is {Concat([Name],;)}"
''' </summary>
''' <remarks>Typically, you would have two arguments, the second one being a constant that separates values in the list. For example, to print "Value1; Value2; Value3" you would use {Concat([Value],; )}
''' If you omit the second argument, it defaults to ", ", so {Concat([Value])} produces "Value1, Value2, Value3".
''' Finally, if you have more than 2 arguments, the separator is computed by joining th remaining arguments with a comma, so {Concat([Value],;,! )} produces "Value1;,! Value2;,! Value3".
''' Another way to use a comma here, as well as with other aggregates, is to substitute it with "&comma;" (in XML it would be "&amp;comma;")</remarks>
Public Class Concat
Implements Core.IAggregateFunction
Private _str As String = String.Empty
Public Sub Current(ByVal ParamArray args() As Object) Implements Core.IAggregateFunction.Current
If args.Length = 0 Then Throw New ArgumentException(Nothing, "args")
Dim Delimiter As String
Select Case args.Length
Case 1 : Delimiter = ", "
Case 2 : Delimiter = args(1)
Case Else
Dim DelimiterArgs(args.Length - 2) As String
Array.Copy(args, 1, DelimiterArgs, 0, args.Length - 1)
Delimiter = String.Join(",", DelimiterArgs)
End Select
If _str = String.Empty Then _str = FixComma(args(0).ToString) Else _str &= FixComma(Delimiter) & FixComma(args(0).ToString)
End Sub
Public ReadOnly Property Value() As String Implements Core.IAggregateFunction.Value
Get
Return Me._str
End Get
End Property
Function FixComma(ByVal arg As String) As String
Return arg.Replace(",", ",")
End Function
End Class
End Namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.