Using Enumerators to Work with Items in a Collection
You can use enumerators to select items from a collection. When the repository engine establishes an enumerator for you, it reads the repository database to determine which items should appear in the list, and the order in which those items should appear. The enumerator does not, however, contain repository items. Rather, each element of an enumerator identifies a repository item. To retrieve a particular item identified by the next element of an enumerator, use the Next method of the enumerator interface.
The elements in an enumerator identify the items in a collection as described by the repository database when the enumerator was instantiated. After you instantiate the enumerator, the collection in the database can change. Specifically, you change a collection in these ways:
- Add an item.
Your enumerator will not refer to the newly added item. To see the new item, you must instantiate the enumerator again.
- Remove an item.
Your enumerator will continue to refer to the deleted item. That is, your enumerator will retain an element that refers to the deleted item by its internal identifier. When you call the Next method to retrieve the item, the method returns an error.
- Reorder the collection.
Your enumerator will reflect the old order. To see the new order, you must reinstantiate the enumerator.