VS Extract Method, vsextractmethod

Source: Internet
Author: User

VS Extract Method, vsextractmethod
Preface

Looking at refactoring 6.4 Replace Temp with Query (replacing temporary variables with queries), Replace Temp with Query is often an essential step before you use the Extract Method,Local variables make the code hard to be extractedExtract Method is a built-in function of VS. I have never used this function from VS2003 to VS2015. I should think about it as a Neter.

During refactoring, it is pointed out that when a function is too long and too largeMany annotationsThis code can be understood and put into an independent function. Therefore, Extract Method is one of the most commonly used refactoring methods. The finer the granularity of each function, then the function is more likely to be reused, and the function is more easily overwritten.

 

Extract Method

1. Extract Method is provided in VS, And the Resharper plug-in also includes this function, in the following sample code, the first line of code in the CalculatePaintNeeded Method can be extracted to a separate Method using the Extracct Method.

 

 

public class ActivityProvider{       const double PI = 3.14;       private double CalculatePaintNeeded(double unit, double radius)        {            double area = PI*radius*radius;            return area;        }}

 

  

 

2. Select the code you want to Extract, right-click Refactor -- Extract Method, and select Resharper in the menu bar to provide the function. The extracted code is as follows: CircleArea.

public class ActivityProvider    {        const double PI = 3.14;        private double CalculatePaintNeeded(double unit, double radius)        {            var area = CircleArea(radius);            return area;        }        private static double CircleArea(double radius)        {            double area = PI*radius*radius;            return area;        }    }

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.