Constructors: CreateEnumerator |
Creates a For..Each compatible wrapper around an IEnumerator interface.
Public Function CreateEnumerator( ByVal Obj As IEnumerator ) As IUnknown
VBCorLib allows for the building of custom enumerators to be used in a For..Each loop context.
To create a custom enumerator please refer to the IEnumerator interface.
In order for Visual Basic to utilize a custom IEnumerator object, it must be wrapped in an object that implements the IEnumVariant interface. This is the only interface that Visual Basic can use in a For..Each context. By passing in the custom enumerator into the CreateEnumerator function, a wrapper is applied and returned that is then returned in the typical NewEnum function of a class.
The following example shows a typical usage of CreateEnumerator within the NewEnum method that an enumerable class implements.
Public Function NewEnum() As IUnknown Dim en As New MyEnumerator en.Init Me Set NewEnum = CreateEnumerator(en) End Function