This seems like something that should be possible, but I am having
trouble setting up a function to accept a generic type as a parameter.
A basic function that shows what I am trying to do:
Public Class BaseRecord(Of T)
Protected _id As Integer
Public ReadOnly Property ID() As Integer
Get
Return _id
End Get
End Property
End Class
Public Class StringRecord
Inherits BaseRecord(Of String)
Private _value As String
Public ReadOnly Property Value() As String
Get
Return _value
End Get
End Property
End Class
Public Class Validation
Public Shared Function ValidateRecord(ByVal record As
BaseRecord(Of Object)) As Boolean
If record.ID < 0 Then
Return False
Else
Return True
End If
End Function
End Class
However, when I try to call the validation function like this:
Dim rec As New StringRecord()
Validation.ValidateRecord(rec)
I get an error stating "Value of type StringRecord cannot be converted
to BaseRecord(Of Object)"
I have tried making the function "Byval record as BaseRecord(Of T)"
but it states that "Type T is not defined"
Is there a way to pass this record as I am attempting or do I need to
completely rethink the way I am wanting to do validation?
Thank you,
Mike