code_junkie

How to dynamically create a object of a generic class?

Nov 13th, 2011
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. Public Sub Save(ByVal obj As IPta)
  2.  
  3. Dim AddressDao as New Generic.PtaDao(of Address)
  4.  
  5. Public Sub Save(Of T As { IPta, New })(ByVal obj As T)
  6. Dim foo As New T
  7. ' Do more stuff here
  8. End Sub
  9.  
  10. Public Sub Save(Of TSomeIPtaType As {IPta, New})(ByVal obj As TSomeIPtaType)
  11. Dim dao As New Generic.PtaDAO(Of TSomeIPtaType)
  12. End Sub
  13.  
  14. Public Sub ExampleUsage()
  15.  
  16. Dim address As New Address
  17.  
  18. Save(address)
  19.  
  20. End Sub
Add Comment
Please, Sign In to add comment