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; } }