The Convert Iterator to Method refactoring provides an opportunity to transform an iterator into a block of code that uses an explicit collection holding iteration result.
- Place the caret at the name of an iterator in the editor, in the File Structure window, in Class View or in Object Browser.
Do one of the following:
- On the main menu, choose ReSharper | Refactor | Convert | Iterator to Method.
- Choose Refactor | Convert | Iterator to Method on the context menu.
- Press Ctrl+Shift+R and click Convert Iterator to Method.
Consider the example below:
After applying the refactoring, you are prompted to specify a name for the collection that holds the result.