JustCode

The Extract Method refactoring allows you to easily create a new method based on a selected code fragment. Extract Method helps you reorganize your code for better reuse and readability.

By analyzing the selected code, Telerik JustCode creates a new method that contains the extracted code and replaces it in the existing member with a call to the new method.

Note

Language Support

Supported: C#, VB.NET

Not supported: JavaScript

Not relevant: ASP.NET, XAML, HTML

You can also watch the video tutorial JustCode - Extract Method.

To extract a method

  1. Select the code fragment you want to extract.

    Extract Method Select
  2. Press Alt+Insert. From the pop-up menu select Extract Method.

  3. Enter a name for the new method.

    Extract Method Created
  4. Press Enter to finish or Esc to abort the operation.

To extract a method with a return statement

Expressions that contain return statements which don't return from all code paths are extracted as methods that return boolean and accept an output parameter.

  1. Select the code fragment you want to extract.

    Extract Method With Return Statement Select
  2. Press Alt+Insert. From the pop-up menu select Extract Method.

  3. Enter a name for the new method.

    Extract Method With Return Statement Created
  4. Notice how Telerik JustCode created a new method returning bool and accepting out parameter. In this way Telerik JustCode ensures that the generated code is compilable.
  5. Press Enter to finish or Esc to abort the operation.
Caution

You cannot extract a method that contains break or continue statement because that could lead to wrong code semantics and/or produce a non-compilable code. You will be warned by Telerik JustCode with a message in the status bar if you try to do that.

Tip

To extract a method you can also navigate on the main menu. Choose JustCode | Refactor | Extract Method, or just press Ctrl+R, Ctrl+M

See Also