[#RESHARPER] Tip: Introduce Variable (an internal #refactoring good good)

Buenas,

he other day was the Victor and I was surprised that he did not know the “Enter Variable” feature of ReSharper .Mainly, because the Victor is a fan of shortcuts keyboards, you want to or not, they increase productivity a lot.

Note: you to be fast with the keyboard, does not mean that you’re a good programmer. The writer is an example of this.

Returning to Introduce Variable, the purpose of this functionality is to create an “internal” refactoring within a method or function. Thinking of the most popular cases of refactoring, this is like an Extract Method, but internal. Here is an example, step by step. Suppose we have the following code:

   1: using System;
   2:  
   3: namespace ClassLibrary2
   4: {
   5:     public class Class1
   6:     {
   7:         public Class1()
   8:         {
   9:             string someValue = Guid.NewGuid().ToString() + " - valentino - " + Guid.NewGuid().ToString();
  10:         }
  11:     }
  12: }

and line 9 is a little confusing to us. If we want to implement the sum of the first 2 parts in another variable we can do the following.

1. Select the parts to work

image

2. Press CTRL + r, CTRL + v, or Enter a Variable option.

image

3 We will have this part of our code in another internal variable to the field where we are working. Where can we also define the data type, name, etc. Just great!

image

 

Saludos @ La Finca

El Bruno

image image image

Leave a comment

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: