あれがこうなる。
yield って素敵。orz
Option Explicit On
Option Strict OnImports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.IONamespace SilverBouquet.IO
Public Class LineEnumerator
Implements IEnumerator(Of String)
Private _reader As TextReader
Private _line As String
Public ReadOnly Property Current() As String Implements System.Collections.Generic.IEnumerator(Of String).Current
Get
Return Me._line
End Get
End Property
Private ReadOnly Property IEnumerator_Current() As Object Implements System.Collections.IEnumerator.Current
Get
Return Me._line
End Get
End Property
Public Sub New(ByVal reader As TextReader)
Me._reader = reader
End Sub
Public Function MoveNext() As Boolean Implements System.Collections.IEnumerator.MoveNext
Me._line = Me._reader.ReadLine
Return Not Me._line = Nothing
End Function
Public Sub Reset() Implements System.Collections.IEnumerator.Reset
Throw New InvalidOperationException("SilverBouquet.IO.LineEnumerator.Reset() can not be called")
End Sub
Private Sub Dispose() Implements IDisposable.Dispose
End Sub
End Class
Friend Class LineEnumerable
Implements IEnumerable(Of String)
Private _reader As TextReader
Public Sub New(ByVal reader As TextReader)
Me._reader = reader
End Sub
Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of String) Implements System.Collections.Generic.IEnumerable(Of String).GetEnumerator
Return New LineEnumerator(Me._reader)
End Function
Private Function IEnumerable_GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
Return New LineEnumerator(Me._reader)
End Function
End Class
Public NotInheritable Class Util
Private Sub New()
End Sub
Public Shared Function ReadLines(ByVal reader As TextReader) As IEnumerable(Of String)
Return New LineEnumerable(reader)
End Function
End Class
End Namespace