[2005] Generic & ParamArray
Hi all,
I m working on project i which i have to make one method which accept multiple parameter of the Generic class. But the problem is while declaring the function.
Let me clear the vision.
Code:
Class SqlParam(Of T)
Public obj As T
Sub New(ByVal parameterName As String, ByVal type As System.Data.SqlDbType, ByVal size As Integer, ByVal value As T, Optional ByVal isNullable As Boolean = False)
'Action
End Sub
End Class
Now I want to make one method in another class that Insert the record in DB using function having ParamArray of Generic Class object.
Like
Code:
Class SqlHelper
Public Sub Insert(ByVal ParamArray parameters() As SqlParam(Of Object))
'Action Here
End Sub
End Class
What should i defined there inplace of Object maked red. Bec'z I want to Achieve this
Code:
Dim objSql As New SqlHelper()
objSql.Insert(New SqlParam(Of String)("@ID", SqlDbType.VarChar, 1000, "Coool"), New SqlParam(Of Integer)("@Total", SqlDbType.Int, 50, 23))
I know there are other methods but I am using generic class bec'z i want type safety. Hope you can focus on this.
Thanks in Advance.
Re: [2005] Generic & ParamArray
Anybody plz.. Is there any alternative way for this but with type safety?
Re: [2005] Generic & ParamArray
What you're asking for is not possible. I'd suggest that you declare a common base class or common interface, then have your generic class inherit or implement that. You can then use that type as the type of your paramarray.
When you define a generic class you're actually defining a whole family of classes. You cannot then declare a parameter whose tpye is a family of classes. It must be one single class out of that family.
Re: [2005] Generic & ParamArray
Thanks for reply. Is there any other method in ur eye which provide the same functonality with type safety?