ReSharper configuration and usage summary and resharper usage Summary

Source: Internet
Author: User

ReSharper configuration and usage summary and resharper usage Summary

1: After the installation, Resharper will use its own smart prompts in English to replace the smart prompts of vs2010. Therefore, we need to switch back to the smart prompts of vs2010.

 

2: shortcut key. Is the shortcut key for vs2010 or for Resharper? I am using the re shortcut key

 

 

3:

After esharper is installed, several things will be done. These things are troublesome for other users. So let's summarize them for reference.

(1) select the option -- text editor -- C # -- General -- automatically list members. In this way, when you use a method, the parameter will not be prompted, which is a very depressing thing.

You can manually hook it up.

(2) The options -- text editor -- C # -- Advanced -- display real-time semantic errors, and underline mark errors in editing are removed. This is nothing, but if Resharper is uninstalled,

The vs editor does not prompt errors in real time. Therefore, After detaching Resharper, you need to re-check the two options.

4: use var

Use implicitly typed local variable declaration

 

 

5: pressing alt + enter can solve many problems. The following describes the shortcut keys.

 

 

6: Alt + F7 display all the variables at the position of your cursor in the form of a list. The form that displays the result can be docked as other forms.

Its advantages include:

You can select to display only read usage or write usage from all usage options. Sometimes we just want to know where a variable is changed. The icon in front of the specified position also tells you this.

You can preview at the bottom, even if we list all the usage, and do not want to jump to every place where you use it, this preview can help you a lot.

When you modify some usage items in the Code Editor, for example, deleting a row, you can use strikethrough to display the results in the form.

By default, all the solutions are used and organized by namespace, making it easy to choose.

I cannot remember how I searched before Alt + F7. I almost forgot to press Ctrl + F unless I forgot the name of a variable. If so, most of the names require refactor, which is another major function of Resharper. Some people may sneer at this function, but those who have used CAB know that the signature for subscribing to and publishing an event is a string. If you don't need to search for it, you don't know how many processing programs are working behind the scenes when you click the mouse of the control. Using Alt + F7 to search for this string is equivalent to all callers behind the search.

However, we recommend that you use Alt + F7 with caution when the cursor stays on a type. If it is a string, you should be able to imagine how many values are used.

7: Powerful Alt + Enter

The omnipotent Alt + Enter can help you complete a lot of dirtywork during code writing. The following is a summary:

Helps you implement an interface or abstract methods of the base class;

Provides suggestions for handling the current warning;

Provide you with some suggestions for handling current errors (not necessarily true errors );

Simplify the current bloated code for you;

8: Ctrl + F11 when we look at other people's code or our own code, we always feel that there are too many code, so we use region to encapsulate and annotate the code, after reading the code, the Resharper File Structure function shows the region and your methods.

After talking about this, it is actually to combine the strengths of the Object Browser and region, which can be clearly classified and clearly identified. Resharper has helped you a lot. Press Ctrl + F11 to bring up a window like the one on the right.

Here, according to your region, people who read your code will also benefit. The parameters and return values of each method are listed in the same way as those of UML.

To browse a method, double-click its name;

If you want to add several methods to a new region, you can select a method and click the icon in the image box on the toolbar; click the cross button to delete the region and move the corresponding method out.

If you want to adjust the position of a method, such as moving it to another region, you just need to drag this method here.

What's more, you want to browse and find all the functions of use and refactoring here. Right-click a method and you will be able to start the operation.

 

 

9: reconstruction is King (on)

Refactoring is a spirit that proves that you are committed to providing efficient, refined, and robust code, rather than messy, obscure, and full-blown code.

In Visual Studio 2005, Microsoft provided the refactoring tool for the first time. But not enough. The refactoring we need is very broad. We want to make quick adjustments to the code, so we can do what I want with my tools. This is the realm of pursuing reconstruction. In this sense, almost Resharper provides you with great productivity.

The refactoring provided by Visual Studio 2005 includes the following:

Encapsulation Field

Extraction Method

Extraction Interface

Promote local variables

Remove Parameters

Rename

Rearrange Parameters

All of these methods are supported in Resharper (but Resharper's refactoring is far more than that), and their corresponding changes are:

Encapsulation Field -- Introduce Field

Extraction Method -- Extract Method

Extract Interface -- Extract Interface (Extract Superclass extraction is added as the base class)

Upgrade the local Variable-Introduce Variable

Remove parameter -- move to Change Signature (Change method Signature)

Rename -- Rename (Resharper will provide you with several optional names based on the object type name)

Rearrange parameters -- move to Change Signature (Change method Signature)

I know that many people claim that E is not good, but it is really a very simple word, it is hard to beat anyone. We know all about these refactoring functions. The Resharper is unique to you. The shortcut key for refactoring is Ctrl + Shift + R:

1. for classes, in addition to the extract interface and base class, you can also move it to other namespaces and to other files. This is a practical function. Maybe you don't believe it, but I have a person who writes all business entity in a DataObject. cs. It's hard to imagine how big your mouth is when I open it.

2. For fields, the following functions are provided:

Safe Delete: detects all used locations and asks how to Delete them;

Pull Member Up and Push Member Down. You can move this field in the base class and inheritance class;

Use base type where possible: Use the base class as much as possible. Because the ArcGIS platform is based on com components, we often need the attributes or methods exposed by interfaces such as IGeometry and IPointCollection, therefore, you do not need to save a polygon object, but you can use the base type;

Encapsulate Field, encapsulation Field, but this function is far from useful for other operations that provide the same function. I can talk about it later.

3. provides the following methods:

Similar to the field function;

Change Signature: changes the function Signature, including changing the name, return value type, parameter information, adding and deleting parameters, which is quite practical. If you are operating on the rewrite method, you will be prompted whether to change it to the base class.

Make Static: If Resharper detects that this method is not associated with a non-static member, it will automatically prompt you (in the form of a yellow horizontal bar) to change to Static, if you modify some methods on your own, you are at your own risk.

Extract class from parameter. If you have seven or eight parameters, do you want to use a class to encapsulate these parameters? So this function came into being.

Method to Property, as the name implies, if you are still using GetField () or SetField (...), you must come from a non-. net star.

4. Inside the method body:

Extract Method. No need to introduce it.

Introduce Variable/Parameter/Field, depending on the object where your cursor is located, can provide the conversion function.

Inline Variable:

IPoint point = new PointClass ();

Point. PutCoords (_ point. X, _ point. Y );

This is the case:

New PointClass (). PutCoords (_ point. X, _ point. Y); // This is a bad example

5. Rename:

The reason for renaming is worth picking out, because Resharper provides the golden feature of naming recommendations. So I want to change my name to the name of Yi Xiaoqiang, which is not so costly. Resharper provides several alternative names based on the type of the variable. The name list is listed at the cursor position (a dialog box is displayed for renaming the method ), you only need to use the direction key to select and press Enter. This type of name is usually obtained by changing the first letter of the type name to lowercase, or even root to the type name of the base class, you can also make improvements on this basis. If you are still using obscure names such as I and j, change them to readable names such as outIndex and pointCount.

Resharper actually provides more advanced functions. When you name a variable, There is a shortcut key to provide you with an alternative name. However, Ctrl + Space is our valuable input method for switching keys, I made a final decision on the variable name, often starting with a bad one, and then renaming it.

There are also some functions that help you adjust the code in a broader sense. I will write another article, or it will be too long.

Reconstruction is King (lower)

Insert Code

The Alt + Insert shortcut keys of Resharper provide you with the function of inserting code. Since these two keys are very hard to press (this is my feeling), when actually using, I am using Alt-R-C-G, which means to open the Resharper menu -- Code -- Generate, you only need your left hand, so that you can draw on one side of your right hand while writing code. how cool it is.

The most common constructor and attribute in the generated code are constructors and attributes. If you do not have a private field, only an empty default constructor is generated and no attribute generation function is available. If you have private fields, you will be asked to select which private fields need to be used as parameters of the constructor and generate the initialization code before generation. This is extremely convenient for writing heavy loads. The property generation is similar.

The second common method is to override the methods of the base class or interface. Select Implement Interface Member or Override Inheritate Member. Resharper searches for the base class or Interface of the current class, and then columns it according to the inheritance level to rewrite or Implement these methods according to your choice.

The Equals and GetHashCode generation methods are not commonly used. In my application scenarios, they are rarely overwritten. However, according to. NET design specifications, both the value type and the Equals of the reference type are recommended to be rewritten, And the GetHaseCode method should be rewritten because they are mutually dependent. If you have this requirement, generating these three functions will certainly help you a lot.

Surround code

Visual Studio also provides the external code function, you can press Ctrl + K, Ctrl + S to activate this function, although I do not mean to despise Visual Studio, but the Resharper shortcut key is indeed more reasonable (it is really difficult to press S when I press Ctrl), and the entry is clearer. In Resharper, the shortcut key for this function is Ctrl + Alt + J. Then you can select to enclose the code of the current row in try-catch Block or using. This is a very efficient method. We tend to try not to capture exceptions in the early stages of development, but to add exception handling mechanisms in the middle and late stages. So you have a lot of work in a certain period of time to expand them into try-catch blocks. The best way to use a dispose object is to use the using block. (When I know that my code is not optimal, I always have a hard time). Here, I naturally have the function of extending the code to the region block, which is also one of the common functions.

Adjust the position of the Method

As I have said before, if you want to adjust the position of the method, you can drag and drop the operation in the code structure window. If you think you just want to move a method to the front, but you have to open the code structure window too heavyweight, there is a lightweight method: When the cursor is on the name of the method, ctrl + Shift + up/down can be used to move the location of the method, including the xml annotation of the method. However, if you use not three/xml annotations but two, sorry.

Other trivial Functions

You will often copy and paste the code of the current line. For example, when using StringBuilder. Append, Ctrl + D can simplify the work of Ctrl + C and Ctrl + V.

Once there was a key combination that could comment out the current row, and another one was to cancel the comment, but I forgot, because Ctrl +/should be the key that really belongs to it, click again to cancel the comment.

With regard to Resharper's refactoring functions, I may be naive to include many additional functions in refactoring, but it does help you quickly adjust and optimize your code. Therefore, do not go into details about the concept of refactoring.

Enhanced browsing Functions

Browsing Parameters

When we enter the method, we are used to the parameter prompts provided by IDE, which greatly facilitates the selection of overload methods. Visual Studio has already done this without Resharper. So why does Resharper need to enhance this function and get high praise. Ask if the narrow line of parameter prompts in Visual Studio make you feel wrong. We have a 19-inch big screen with a 1600 resolution, but we have to stare at the narrow bar and carefully press the up and down key to find the heavy load we need. At least, the developer of Resharper cannot accept this type of error. Therefore, the parameter list of the large version is displayed, and long parameter reloads are displayed in the form of lists, when you are using the GDT + method and see huge parameter overloading, you will sigh from the bottom of your mind: selling cakes.

At the same time, the shortcut key of the Resharper display parameter is changed to Ctrl + P. If you think it is a joke to block the printed shortcut key, ask yourself how many times you have printed your code.

Browse open documents

I thought you already know how to switch documents in Visual Studio. They include:

Ctrl + Alt + up and down arrow keys, which can be switched in the open document;

Ctrl + Tab: you can switch to the solution folder and attribute view before the document, and press the Left or Right key.

But how can I open the file that was closed after the recent editing? Visual Studio does not provide this function very politely, so it is reserved for Resharper. Here, the shortcut keys are Ctrl + E and Ctrl + E. That's right. Press them twice. If not, check the Resharper-View-Recent Files menu to see what it is. Because it is often used by you. Open a file list, select it with the arrow key, and press enter to open it in the editor.

Many people say that Resharper has a performance problem. One possible reason is that too many documents are opened. If you have the habit of closing unnecessary documents at any time, the performance may not be so bad, in addition, you can open these closed documents at any time, just as easily switching between opened documents.

I didn't use agile development in my team, but we kept the good habit of every change involving only two or three files, and frequently commite to the source code server. Therefore, each time I really want to edit a small number of files, the performance is not a problem.

I have shared with you a lot of Resharper's skills, and I have already integrated my daily development work. Of course, it is not comprehensive. For example, the integration with Nunit, because we are not a test-driven platform, we do not have any experience, and naturally do not dare to give a comment. It is also subjective. I think it is good, you may think it is not good. Radish vegetables have their own love. Besides, it is not an idiot. Right-click on the document and add the "Close All" function to Close All opened documents. What are you doing when you Close the file? Are you staring at a blank screen? I think the native "close all of this" is enough. There is also a Locate in Solution Explorer function, which is useless. If you set it in the VS option, track the activity item in Solution manager, then VS automatically positions you.

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.