G
Guest
Hi,
I have been passed a class to work with, but am having some problems. I do
not know the origin of the code, and am having problems with some
functionality.
The VB class implements IEnumerable, which I understand allows for fwd only
movement through the custtom collection. This work fine and I am able to use
"For Each" loops without issue. However, the class has MoveFirst(),
MoveLast() etc methods within it, but these do not appear to be exposed, and
are therefore unavailable. Is the IEnumerable interface restricting these
methods somehow, or is the class missing elements.
So, How do I implement MoveFirst(), MoveNext() with the following class(s)?
Many Thanks,
Duncan.
************************************************************
Imports Microsoft.VisualBasic
Public Class Raters
Implements System.Collections.IEnumerable
Private m_Raters As ArrayList = New ArrayList
Private m_CurrentIndex As Integer = -1
Private m_Count As Integer = 0
Private m_CandidateId As Integer = 0
Public ReadOnly Property Count() As Integer
Get
Return m_Count
End Get
End Property
Public Sub Add(ByVal Rater As Rater)
m_Raters.Add(Rater)
m_Count += 1
End Sub
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return New RatersEnumerator(Me)
End Function
Public Function MoveNext() As Boolean
Me.GetEnumerator.MoveNext()
End Function
Public Function MoveFirst() As Boolean
'*???*
End Function
Public Class RatersEnumerator
Implements IEnumerator
Private m_Raters As Raters
Public Sub New(ByVal Raters As Raters)
m_Raters = Raters
Me.Reset()
End Sub
Public ReadOnly Property Current() As Object Implements
System.Collections.IEnumerator.Current
Get
Return m_Raters.m_Raters(m_Raters.m_CurrentIndex)
End Get
End Property
Public Function MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count - 1)) Then
Return False
Else
m_Raters.m_CurrentIndex += 1
Return True
End If
End Function
Public Function MovePrevious() As Boolean
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count + 1)) Then
Return False
Else
m_Raters.m_CurrentIndex -= 1
Return True
End If
End Function
Public Function MoveFirst() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = 0
Else
m_Raters.m_CurrentIndex = -1
End If
End Function
Public Function MoveLast() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = m_Raters.m_Raters.Count
Else
m_Raters.m_CurrentIndex = -1
End If
End Function
Public ReadOnly Property Count() As Integer
Get
Return m_Raters.m_Raters.Count()
End Get
End Property
Public Sub Reset() Implements System.Collections.IEnumerator.Reset
m_Raters.m_CurrentIndex = -1
End Sub
End Class
End Class
************************************************************
I have been passed a class to work with, but am having some problems. I do
not know the origin of the code, and am having problems with some
functionality.
The VB class implements IEnumerable, which I understand allows for fwd only
movement through the custtom collection. This work fine and I am able to use
"For Each" loops without issue. However, the class has MoveFirst(),
MoveLast() etc methods within it, but these do not appear to be exposed, and
are therefore unavailable. Is the IEnumerable interface restricting these
methods somehow, or is the class missing elements.
So, How do I implement MoveFirst(), MoveNext() with the following class(s)?
Many Thanks,
Duncan.
************************************************************
Imports Microsoft.VisualBasic
Public Class Raters
Implements System.Collections.IEnumerable
Private m_Raters As ArrayList = New ArrayList
Private m_CurrentIndex As Integer = -1
Private m_Count As Integer = 0
Private m_CandidateId As Integer = 0
Public ReadOnly Property Count() As Integer
Get
Return m_Count
End Get
End Property
Public Sub Add(ByVal Rater As Rater)
m_Raters.Add(Rater)
m_Count += 1
End Sub
Public Function GetEnumerator() As System.Collections.IEnumerator
Implements System.Collections.IEnumerable.GetEnumerator
Return New RatersEnumerator(Me)
End Function
Public Function MoveNext() As Boolean
Me.GetEnumerator.MoveNext()
End Function
Public Function MoveFirst() As Boolean
'*???*
End Function
Public Class RatersEnumerator
Implements IEnumerator
Private m_Raters As Raters
Public Sub New(ByVal Raters As Raters)
m_Raters = Raters
Me.Reset()
End Sub
Public ReadOnly Property Current() As Object Implements
System.Collections.IEnumerator.Current
Get
Return m_Raters.m_Raters(m_Raters.m_CurrentIndex)
End Get
End Property
Public Function MoveNext() As Boolean Implements
System.Collections.IEnumerator.MoveNext
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count - 1)) Then
Return False
Else
m_Raters.m_CurrentIndex += 1
Return True
End If
End Function
Public Function MovePrevious() As Boolean
If (m_Raters.m_CurrentIndex = (m_Raters.m_Raters.Count + 1)) Then
Return False
Else
m_Raters.m_CurrentIndex -= 1
Return True
End If
End Function
Public Function MoveFirst() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = 0
Else
m_Raters.m_CurrentIndex = -1
End If
End Function
Public Function MoveLast() As Boolean
If (m_Raters.m_Raters.Count() <> -1) Then
m_Raters.m_CurrentIndex = m_Raters.m_Raters.Count
Else
m_Raters.m_CurrentIndex = -1
End If
End Function
Public ReadOnly Property Count() As Integer
Get
Return m_Raters.m_Raters.Count()
End Get
End Property
Public Sub Reset() Implements System.Collections.IEnumerator.Reset
m_Raters.m_CurrentIndex = -1
End Sub
End Class
End Class
************************************************************