Click here to Skip to main content
15,885,998 members
Articles / Desktop Programming / Windows Forms

Object-oriented Printing with Inka, Part 1

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
27 Feb 2009LGPL35 min read 34.3K   396   28  
The basics of Inka, an open source printing component
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 "&amp;comma;" (in XML it would be "&amp;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("&comma;", ",")
        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.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer GeekSoft
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions