ReSharper Help

Convert Iterator to Method

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.

To convert an iterator to a method

  1. Place the caret at the name of an iterator in the editor, in the File Structure window, in Class View or in Object Browser.
  2. 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:

Refactorings__Convert_Iterator_to_Method_01
After applying the refactoring, you are prompted to specify a name for the collection that holds the result.
Refactorings__Convert_Iterator_to_Method_02

This feature is supported in the following languages/technologies:

C# VB.NET C++ HTML ASPX Razor JavaScript TypeScript CSS XML XAML RESX Build Scripts
feature_available feature_available

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by Language section.

See Also

Reference:

Last modified: 8 April 2015
comments powered by Disqus