Using IndexedEnumerable in CodeSmith 5.1

Let’s take a quick look at a new feature in CodeSmith called IndexedEnumerable. IndexedEnumerable provides a smarter way to iterate collections. The best way to see this is with a quick sample. We will get a list of tables and iterate the collection as an indexedenumerable.

A template is attached containing the code you see here. Run the template against the Petshop Database located in the CodeSmith samples folder, you can see IndexedEnumerable at work.

When you need to know where you are while iterating a collection, Turn your collection into an IndexedEnumerable and it will make life much easier when making decisions based on the index of the current item in the collection.