J
Jakob Lithner
I have searched the news groups on similar subjects, but
haven't found anything adequate for my need ....
To save much duplication of code I would like to create a
baseclass that takes a SQL-Select-string and a type as
parameters. It will then return a collection of objects of
the specified type. (I have ~30 object types that will be
fetched in exactly the same way from one table each).
Dynamic parsing works fine using the Reflection namespace,
but the instantiation of objects seems to be tricky.
I would like to do something like:
Private Shared Function GetMessage(ByVal myType As
System.Type, ByVal collectionType As
IMessageCollectionBase, ByVal strSQL As String) As
Collection
Dim o as object
'Call DB and get datareader ...
While dr.read()
o = New myType
o.Parse(dr)
collectionType.Add(o)
End While
Return collectionType
End Function
Is it possible at all?
haven't found anything adequate for my need ....
To save much duplication of code I would like to create a
baseclass that takes a SQL-Select-string and a type as
parameters. It will then return a collection of objects of
the specified type. (I have ~30 object types that will be
fetched in exactly the same way from one table each).
Dynamic parsing works fine using the Reflection namespace,
but the instantiation of objects seems to be tricky.
I would like to do something like:
Private Shared Function GetMessage(ByVal myType As
System.Type, ByVal collectionType As
IMessageCollectionBase, ByVal strSQL As String) As
Collection
Dim o as object
'Call DB and get datareader ...
While dr.read()
o = New myType
o.Parse(dr)
collectionType.Add(o)
End While
Return collectionType
End Function
Is it possible at all?