Resharper advanced 7: refactoring is King (bottom)

Source: Internet
Author: User
InsertCode
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.

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.