Archive for the ‘Refactor’ Category

Refactorings – Sort Namespace References

April 18th, 2011 Comments off

The Sort Namespace References refactoring is a stand-alone part of the Optimize Namespace References refactoring. In contrast to that refactoring, the Sort Namespace References refactoring doesn’t remove any references, and as the name says, it just sorts the ‘using’s (C#) or ‘Imports’ (VB) statements in the active source file.

The following sorting methods are available:

  • Alphabetically
  • By Length

Read more…

Refactorings – Optimize Namespace References

April 15th, 2011 Comments off

The Optimize Namespace References refactoring removes namespace references (usings (in C#) or Imports (in VB)) that are not needed in the active source file, either because they were added automatically and not used, or because the code that did require them has been removed or relocated. Also, it can automatically sort used references after refactoring is performed: alphabetically, by length or not sort. An additional sorting option is to move all System references at the top of the list (file). The refactoring improves code readability.

Read more…

Refactorings – Flatten Conditional

March 22nd, 2011 Comments off

This is one of the most powerful refactorings for conditionals – it helps you to simplify conditional statements by unindenting all or a portion of the conditional statement which improves the clarity of the code. This refactoring includes several different refactorings mentioned in Martin Fowler‘s book, and a few others. These refactorings are applied, depending on the conditional blocks you have inside the source code. Here they are:

Read more…

Refactorings – Inline Method

February 17th, 2011 Comments off

The Inline Method refactoring lets you move the method’s body into the body of its callers and remove the method declaration, if needed. Inline Method is helpful when you have a group of methods that seem badly factored. You can inline them all into one big method, and then re-extract the methods.

Another reason to use Inline Method is that sometimes you do come across a method in which the body is as clear as the name. Or, you refactor the body of the code into something that is just as clear as the name. When this happens, you should then get rid of the method.

Read more…

Code Providers – Add Contract

February 7th, 2011 Comments off

Add Contract code provider adds conditions (contracts or guard code) for a validation of the active method parameters. You can choose the preferred contract via the sub-menu of the Add Contract:

Refactor! Add Contract with sub-menu

Read more…

Refactorings – Move Type to File

January 19th, 2011 Comments off

The Move Type To File refactoring allows users to move a given class, structure, interface, enumeration or delegate to a separate file. It is available when there are two or more types in the current source file.

Refactoring moves a type with a name that differs from the file name to a new source file. All comments, attributes, and XML doc comments relating to the type are moved with the type. The file will be located in the same folder as the current file and automatically added to the project. The name of the new file is based on the type’s name on which refactoring is applied.

Read more…

Refactorings – Rename

December 25th, 2010 Comments off

This refactoring provides an easy way to rename identifiers for code symbols such as locals, type members, types or namespaces and updating all their references.

Rename is one of the most useful refactorings of all. The developer can alter the name of the declaration and its occurrences (references) in the code in the whole solution.

Simply put the caret on the identifier and apply the refactoring. The refactoring will wrap all references and name of the declaration into linked identifiers, that help you easily change all occurrences simultaneously. The preview hint in Rename will show visible references in the code editor. Press Enter when you are done changing the name of the identifier to commit your changes.

Read more…

Refactorings – Extract Interface

October 25th, 2010 Comments off

Extract Interface is a refactoring that provides an easy way to create a new interface with members that originate from an existing class or struct.

When several clients use the same subset of members from a class or struct, or when multiple classes or structs have a subset of members in common, it can be useful to embody the subset of members in an interface. The Extract Interface will help to create the new interface for you. Just place the caret on the type name and perform a refactoring.

Read more…