I have several different lists I want to call. They all have the same format for the class: id, value, description, order. Instead of creating a bunch a classes to return the all of the many lists, I wanted to use generics and just TELL it what kind of list to return. However, I can not figure out how to populate the classes.
Here are 2 examples of function in my calling code. This should indicate the type of list and the stored proc used to get the data:
Public Function getTheEyeColors()
Dim glEyeColors As New GenericList
Return glEyeColors.GetALList(Of EyeColor)("GetAllEyeColors")
End Function
Public Function getTheHairColors()
Dim glHairColors As New GenericList
glHairColors.GetALList(Of HairColor)("GetAllHairColors")
End Function
And here is the code I am trying to use to build the generic list...
Public Function GetALList(Of t)(ByVal storedproc As String) As List(Of t)
Dim lstGenericList As New List(Of t)
Dim oGenericListItem As t
Dim oProviderFactory As New ProviderFactory
Dim oConnection As DbConnection
Dim oReader As System.Data.IDataReader
Dim oFactory As DbProviderFactory
Dim oFileMgt As New FileMgt
Dim oCmd As DbCommand
oFactory = oProviderFactory.GetFactory
oConnection = oProviderFactory.GetProviderConnection(oFactory)
oCmd = oConnection.CreateCommand
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = storedproc
Using (oConnection)
oConnection.Open()
oReader = oCmd.ExecuteReader()
While oReader.Read
HERE IS WHERE I AM NOT SURE HOW TO POPULATE THE EYECOLOR OR HAIRCOLOR CLASS
lstGenericList.Add(oGenericListItem)
End While
oConnection.Close()
End Using
Return lstGenericList
End Function