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, 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
Select the code fragment you want to extract.
Press Alt+Insert. From the pop-up menu select Extract Method.
Enter a name for the new method.
- 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.
Select the code fragment you want to extract.
Press Alt+Insert. From the pop-up menu select Extract Method.
Enter a name for the new method.
- Notice how JustCode created a new method returning bool and accepting out parameter. In this way JustCode ensures that the generated code is compilable.
- 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 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