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