The problem here isn't converting an extension method - it's converting an iterator block (the method uses yield return
. VB doesn't have any equivalent language construct - you'd have to create your own implementation of IEnumerable<T>
which did the filtering, then return an instance of the class from the extension method.
That's exactly what the C# compiler does, but it's hidden behind the scenes.
One point to note, which might not be obvious otherwise: IEnumerator<T>
implements IDisposable
, and a foreach
loop disposes of the iterator at the end. This can be very important - so if you do create your own implementation of this (and I'd recommend that you don't, frankly) you'll need to call Dispose
on the iterator returned from source.GetEnumerator()
in your own Dispose
method.