SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

Refactoring

"Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure."

Martin Fowler

SharpDevelop supports the following refactorings.

  • Rename - you can rename a variable, class, method, field or property and all references to it are updated.
  • Remove unused import statements - removes all the unused using or import statements from the current file.
  • Extract method - creates a new method from the selected lines of code.

Given the code:

Code to refactor

You decide that the Count property is badly named and you want to change it, but it is used in several other classes. Right click the Count property and under its name in the menu select Rename.

Refactor rename menu item

This opens the Rename dialog box.

Refactor rename dialog

Type in a new name for the property and click the OK button. This renames the property and updates all the code that uses this property.

To remove any unused import statements from the currently open file, select Remove unused import statements from the Refactor menu.

Remove unused import statements menu item

Given the code:

Code to refactor with extract method refactoring

You decide that the code inside the constructor should be extracted into its own method. Highlight the lines of code you want to extract.

Extract method code selected

From the Refactor menu select Extract Method.

Extract method menu item

In the Extract Method dialog give the method a name and click the OK button.

Extract method dialog

Then a new method will be generated as shown below.

Refactored extract method code

< previous | home | next >

Published Jul 05 2006, 11:55 AM by MattWard
Filed under:

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.