M
Mike
Folks, I have two classes with IEnumerators which differ by Type and
The Function that is used to access data. I want to make this a
generic class:
Public Class WildcatData(Of [T])
Implements IEnumerator, IEnumerable
private tid as integer = 0
private keysort as integer = 0
private data as [T]
Public Sub New(optional key as integer = 0)
KeySort = key
End Sub
Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator
Reset()
Return CType(Me, IEnumerator)
End Function
Public Function MoveNext() As Boolean _
Implements IEnumerator.MoveNext
if TypeOf(data) is TUser then
Return GetNextUser(keysort, data, tid)
end if
if TypeOf(data) is TFileRecord then
Return GetNextFile(keysort, data, tid)
end if
End Function
Public Sub Reset() Implements IEnumerator.Reset
tid = 0
End Sub
Public ReadOnly Property Current() As Object _
Implements IEnumerator.Current
Get
Return data
End Get
End Property
End Class
The compiler is issuing errors:
error BC30311: Value of type 'T' cannot be converted to 'TUser'.
Return GetNextUser(keysort, data, tid)
~~~~
error BC30311: Value of type 'T' cannot be converted to 'TFileRecord'.
Return GetNextFileRec(keysort, data, tid)
~~~~
I tried various CType, DirectCast ways but it all comes down to the
same type conversion error. How do I convert these?
Or is there a more better way to generalize that MoveNext() methods so
it isn't locked to these two types?
Thanks
The Function that is used to access data. I want to make this a
generic class:
Public Class WildcatData(Of [T])
Implements IEnumerator, IEnumerable
private tid as integer = 0
private keysort as integer = 0
private data as [T]
Public Sub New(optional key as integer = 0)
KeySort = key
End Sub
Public Function GetEnumerator() As IEnumerator _
Implements IEnumerable.GetEnumerator
Reset()
Return CType(Me, IEnumerator)
End Function
Public Function MoveNext() As Boolean _
Implements IEnumerator.MoveNext
if TypeOf(data) is TUser then
Return GetNextUser(keysort, data, tid)
end if
if TypeOf(data) is TFileRecord then
Return GetNextFile(keysort, data, tid)
end if
End Function
Public Sub Reset() Implements IEnumerator.Reset
tid = 0
End Sub
Public ReadOnly Property Current() As Object _
Implements IEnumerator.Current
Get
Return data
End Get
End Property
End Class
The compiler is issuing errors:
error BC30311: Value of type 'T' cannot be converted to 'TUser'.
Return GetNextUser(keysort, data, tid)
~~~~
error BC30311: Value of type 'T' cannot be converted to 'TFileRecord'.
Return GetNextFileRec(keysort, data, tid)
~~~~
I tried various CType, DirectCast ways but it all comes down to the
same type conversion error. How do I convert these?
Or is there a more better way to generalize that MoveNext() methods so
it isn't locked to these two types?
Thanks