Posted by: Cirilo Meggiolaro | 10/18/2008

Tip of the day #4 – Refactoring – Extract method

Visual Studio has a very nice set of tools to help you refactor your project’s source code. I have worked with application migrations and the Extract Method feature is my second favorite, after the Rename of course.

It is really easy to use and after few steps your new method will be ready:

1. Select the code you want to extract;

2. Right-click over the selection or go to Refactor menu > Extract Method;

Picture 1 – Accessing refactor feature with right-click.

Picture 2 – Accessing refactor feature on Refactor menu.

3. On the the Extract Method window, type the new method name and press OK;

Picture 3 – Typing the new method name.

4. To finalize just edit the variable names you need;

5. Don’t forget to add a summary and region to your method. It is fast to apply, make your code easier to understand and ready to be documented.

Enjoy it!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: