I am creating an Immutable Linked List class in VBA. It provides ToArray
and ToCollection
methods, which I have both verified as working. However
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Set NewEnum = ToCollection.[_NewEnum]
End Property
ToCollection
is returning a new collection every time it's called; this would probably work:
Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Static internalCollection As Collection
If internalCollection Is Nothing Then Set internalCollection = ToCollection
Set NewEnum = internalCollection.[_NewEnum]
End Property
...but it's rather ugly. Ideally you'd have some instance-level encapsulated As Collection
to return the [_NewEnum]
value from.