Perfect!!! Thanks. I swear I was thinking on the same lines of using an
interface but could not get anywhere further. Anyways, for the record, here
is the new parameterized function:

    Private Shared Function AssembleData(Of TInfo, TData, TAssemblerFactory
As {Class, IAssemblerFactory(Of TInfo, TData), New})( _
                 ByVal dataList As List(Of TData) _
               ) As List(Of TInfo)

        'Return permissions
        Dim infoList As New List(Of TInfo)
        Dim info As TInfo
        Dim factory As TAssemblerFactory

        For Each data As TData In dataList
            factory = New TAssemblerFactory
            info = factory.CreateNew(data)
            infoList.Add(info)
        Next

        Return infoList
    End Function


    Interface IAssemblerFactory(Of TInfo, TData)
        Function CreateNew(ByVal data As TData) As TInfo
    End Interface


    Public Class InfoAssemblerFactory
        Implements IAssemblerFactory(Of UserInfo, UserInfoData)
        Public Function CreateNew( _
                  ByVal data As UserInfoData _
                ) As UserInfo Implements IAssemblerFactory(Of UserInfo,
UserInfoData).CreateNew

            Return New UserInfo(data)
        End Function

    End Class
Thank you so much for taking the time to find me the online link.
Now my code will look a lot more cleaner. I just cant wait till I change it
first thing in the morning.

Cheers!
KP

On 11/19/08, Cerebrus <[EMAIL PROTECTED]> wrote:
>
>
> This is a commonly encountered problem. I recall reading a MS feedback
> site voicing the lament that Generics in .NET should support
> parameterized constructors. Unfortunately, you need to make do with
> workarounds.
>
> One way that I may have used in the past is to apply an interface as
> constraint. This method is elaborated upon in the book "Essential C#
> 2.0".
>
> However, I was able to find an online link to the said chapter for
> you:
>
> See Listing 11.31:
> http://www.codeproject.com/KB/books/EssentialCS20.aspx
>
> KP wrote:
>
> > Hi Guys,
> >
> > I was trying to make the following function a typed one like a TInfo
> > and a TData. But ran out of ideas. Can anyone help? Am I trying to do
> > something that is not possible...at all?
> >
> >         Private Shared Function AssembleData( _
> >                   ByVal dataList As List(Of PermissionInfoData) _
> >                 ) As List(Of PermissionInfo)
> >
> >             Dim permissions As New List(Of PermissionInfo)
> >
> >             For Each data As PermissionInfoData In dataList
> >                 permissions.Add(New PermissionInfo(data))
> >             Next
> >
> >             Return permissions
> >         End Function
> >
> > Note that the TInfo class would be having a constructor that takes a
> > TData to populate itself. This is what I tried:
> >
> >         Private Shared Function AssembleData(Of TInfo As {Class, New},
> > TData)( _
> >                   ByVal dataList As List(Of TData) _
> >                 ) As List(Of TInfo)
> >
> >             'Return permissions
> >             Dim infoList As New List(Of TInfo)
> >             Dim info As New TInfo(TData)
> >
> >             For Each data As TData In dataList
> >                 infoList.Add(info)
> >             Next
> >
> >             Return infoList
> >         End Function
> >
> > Thanks.

Reply via email to