I am trying to get my head around .NET generics and need the help of a guru. Here is my code thus far:
Protected Function GetListFromSP(Of T As New)(ByVal cmd As MySqlCommand) As List(Of T)
Dim conn As New MySqlConnection(Me.ConnectionString)
Dim reader As MySqlDataReader
Dim list As New List(Of T)
cmd.Connection = conn
reader = Me.ExecuteReader(cmd)
If reader.HasRows Then
Dim rec As IDataRecord
For Each rec In reader
list.Add(New T(rec)) ' PROBLEM HERE
Catch ex As Exception
If LogExceptions Then WriteToEventLog("SWReports", "Application", "MySQLAccountProvider: " & ex.Message, Diagnostics.EventLogEntryType.Error)
It appears that generics do not allow the creation of an object with a parameterized constructor. My questions: (1) Is it possible to do this; and (2) if not, all of my objects have parameterless constructors -- how do I set properties of T?
Thanks in advance for any help you can provide.