Is this a bad idea?
Private Class GH_DataStructureEnumerator(Of Q As Types.IGH_Goo)
Implements IEnumerable(Of Q)
Implements IEnumerator(Of Q)
....
....
'Current, MoveNext, Reset etc.'
....
....
Public Function GetEnumerator_Generic() As IEnumerator(Of Q) _
Implements IEnumerable(Of Q).GetEnumerator
Return Me
End Function
End Class
This class is only visible as an IEnumerable(Of T) readonly property, and it saves me an additional class that wraps IEnumerator(Of T). But somehow it just seems wrong. Is there a better way?
Definitely a bad idea. In particular, it means that two calls to GetEnumerator
will return references to the same object - when they should return independent iterators.
Now having said that, the C# compiler will generate classes which implement both types if you use iterator blocks... but it goes to great lengths to make sure that it gets it right. I suggest you don't put yourself through that pain :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With