10 of my favorite CodeRush features for .NET development in Visual Studio


    In short, DevExpress CodeRush is a paid plug-in for Visual Studio related to the productivity tools class, which allows the developer to write faster, better code, debug it, run tests, detect defects and perform other useful functions.

    In this article, I tried to collect not only a list of my own preferences for its use, but also conduct a small validation so that most of the presented chips were used by other guys in my team at the output. I believe that even despite the active development of Visual Studio (the 2012 version was especially pleased) and the conversion of some of the described functions to native ones, the need for third-party helpers such as CodeRush and ReSharper is still relevant for some developers, as it saves time and improves overall usability coding. Finally, do not forget that there are still enough developers sitting on Visual Studio 2010- (at least judging by many customers) due to the characteristics of the project, budget, or just habit.

    So, who is interested to know what other .NET developers use to improve the efficiency of the small, but no less exciting part of the software design process, please welcome the cat (attention, many pictures and videos, as well as a poll!) I


    warn you in advance that my "hot ten" demonstrates only a small fraction of the capabilities of the product (to myself I think that I use less than 5%). For the reader’s convenience, in addition to the Russian functional names, I will give English names typical of a programmer’s ear, indicate default keyboard shortcuts (if any), and also indicate in some places analogues among standard studio features.

    1. Collapse the project tree in Solution Explorer for Visual Studio 2010- / Collapse To Projects


    Often you have to work with large solutions consisting of dozens of projects, and therefore this function is simply irreplaceable to find the right place in the project:



    I have been using it for several years in different versions of Visual Studio and so far I am very pleased (before this opportunity I used a VB macro, in the latest versions of the studio the macros were cut, EMNIP). I hope that this small function will also be useful to some people, since not all projects still use Visual Studio 2012+, where the integrated Collapse All button appeared right in the Solution Explorer:



    2. Quick file navigation in the solution / Quick File Navigation ( Control + Alt + F )


    It is not uncommon for you to know a file with source code by name and want to get into it quickly. To do this, the Control + Alt + F command is simply irreplaceable, which allows you to make the transition as quickly as possible:



    Starting with Visual Studio 2012, a similar function is available in Solution Explorer:



    3. Quick navigation by types and members in the solution / Quick Navigation ( Control + Shift + Q )


    This option is very similar to the previous one, the only difference is that we are no longer navigating through files, but across all types and their members:



    Frankly, if the solution is simply huge, then calling this search dialog without any additional settings can give a noticeable lag for obvious reasons. To avoid this, I recommend conducting a small search tuning (by type and member type, access and region), which will help get rid of garbage results and also increase responsiveness. Of course, it would be even better if the list was not rebuilt on every call, but cached before rebuilding (we need to invite our IDE team to make such an option).

    As an alternative, I sometimes use the good old studio search, for example Control + Shift + F on the line “ss ClassName”, which in principle also works well. Also, the standard Navigate To (Control +,) chip is convenient for this purpose , but I use it much less often:



    4. Navigating the use of types and members / Tab To Next Reference ( Tab / Shift + Tab )


    This is probably one of my favorite features! It allows you to quickly find out where and how a type or member is used: for example, where does this method come from. To do this, simply place the cursor on the desired object in the code and press Tab (forward) or Shift + Tab (back), which is very natural and understandable for any Windows user:



    There are standard studio contractions (Control + Shift + Arrow Up / Down) for the same, but they cause a little pain in my left hand, although, of course, you can reconfigure all this for yourself.

    5. Optimize Namespace References ( Control + ~ )


    I like to get rid of unnecessary using in the files that I visit, and make everything look beautiful and neat. If you are the same using-nazi as I am, then this feature is for you:



    Although this feature appeared back in Visual Studio 2008 (the Organize Usings command from the context menu), I still use the encoder functionality, as it seems more convenient due to highlighting and a faster call.

    It is worth noting that in the settings you can select the default sort, for example, I have the length, instead of alphabetical:



    6. Code Analysis & Formatting / Code Analysis & Code Style ( Control + ~ )


    In short, this studio-built tool is essentially FxCop + StyleCop in one bottle of steroids, which is visually represented by a thin bar on the right in the Code Editor:



    This strip unobtrusively shows multi-colored serifs (color indicates the severity of the problem), indicating to the programmer about possible problems in the code. A complete list of diagnosed problems (including even duplicate code in the solution!) Can be found here .
    As with other similar tools, this assistant can be flexibly configured for you or the code rules accepted by the company so that only the necessary tips are displayed:



    And finally, if you trust the analysis engine as your wife :-), then in the menu for the file in Solution Explorer there is a magic command Code Cleanup , which will automatically “clean” the problems found for you. But, to be honest, I never use this command, because I don’t like it when someone completely automatically corrects the code for me. I remember even making an offer to the guys to add a confirmation dialog for this command, since it seems pretty serious to me (to avoid accidental clicks in the context menu).

    As for the search duplikatnogo code (Duplicate Code Detection and Consolidation) and formatting, then I use these chips much less often and I will not particularly focus on them, just leave links for those who are interested.

    In general, this built-in code analysis is a pretty tolerable initial defense against a fool or the keen eye of a pair programming partner, if you like. I think it will be especially useful for beginner .NET developers.
    In conclusion, it is worth noting that in addition to the previously mentioned FxCop / StyleCop with Visual Studio 2012, the Code Analysis window has appeared that performs similar functions:



    7. Removing type to file, renaming type or file / Move Type To File, Rename, Rename File to Match Type ( Control + ~ )


    Many people consider it good practice to have only one public class in one source file, and if this is not the case, then the Move Type To File command will help to fix this as quickly as possible. A related Rename File to Match Type command allows you to rename a file by the name of the type located in it, if suddenly their names do not match. And finally, you can rename any type or member through the intuitive pressing of F2, after placing the cursor on the desired element:



    8. Adding base type constructors / Add Missing Constructors ( Control + ~ )


    Often during inheritance, it is necessary to implement constructors of the basic type with a bunch of parameters that it would be preferable not to type yourself, but it is better to copy it from somewhere or get it automatically. This command allows you to do all the routine work in one mouse click or in a couple of keystrokes on the keyboard:


    Before that, I usually navigated to the base type declaration through F12 and copied the signature of its constructors.

    9. Removal of a method or variable / Extract Method, Widen Scope ( Control + ~ )


    Very often it is necessary to simplify a method or make the scope of a variable wider. I prefer CodeRush features for these tasks:



    , although it’s probably worth mentioning that the same thing, but a little less convenient, can be done through the built-in refactor:



    10. Templates for fast code generation / Code Generation Templates


    Here I would like to list the abbreviations most often used by me, which are probably useful in almost any program:
    • ss - adds a constructor to the type. Despite its simplicity, this is a pretty smart template, which, unlike the standard one, analyzes type members and suggests adding them as parameters, which is often convenient.
    • f - adds a for loop, and can automatically take the upper bound from a variable previously copied to the clipboard, for example, a collection.
    • fe - adds a foreach loop, and can automatically calculate the type of an element from a variable previously copied to the clipboard, such as a collection.
    • r ?, p? - Adds a new type property, which is usually selected by the first letter. For example, p will make properties of type object, pi will make properties of type int, pd will make properties of type double, pb will make bools and so on. If a read-only property is needed, then r is used instead of p, for example rb.
    • x?
      By the nature of my work, I often create data models for our XAF and XPO frameworks, so I use special templates that start with x (xc, xp ?, xr ?, xpcl, xpa by default)


    The video shows all the above combinations in action:



    With these abbreviations by the first letter, everything is intuitively simple and understandable, except for the only exception that usually makes me smile: if I use the pdt template, which in my world should produce a property of type DateTime, then we get a property of type DataTable at the output - it doesn't look very similar to the most commonly used type by developers around the world :-). For the very same DateTime “thin” pd8 is used (from a similar sounding date c “d” + “eight” in English). Fortunately, all this can again be flexibly configured through the settings dialog, in which you can also create your own templates:



    Of course, these are not all templates or abbreviations, and who are interested, you can look at the full list here or call directly in Visual Studio using the combination Control + Alt + / (although I honestly doubt that anyone in the world uses 20% of the total of these abbreviations).

    In terms of abbreviations, I can say a bit of a non-standard orientation, since I manage to use both standard studio tools (Insert Code Snipped, which is Control + K + X) and Koderashevsky at the same time, though they hardly overlap:



    eleven.
    Unload CodeRush for certain projects


    It's probably no secret to anyone that any extensions for Visual Studio, no matter how good they are, do not speed up the work of the IDE itself. What can I say, when it comes to manipulating simply huge decisions, for example from 80 or more projects - in such cases the “pure” studio itself can barely move, not like with plug-ins ... At such moments, even for the most loyal users, yes the thought creeps in as soon as possible to turn off all additional whistles, well, or somehow minimize their effect:



    In particular, it would be very useful for me to be able to include CodeRush functions only for the right projects, with which, for example, you most often work. Now there is no such chip, but if it were, then it would definitely have got into my favorite list, therefore it occupies an honorable eleventh place, albeit virtual :-)

    Of course, these are not all the chips that I use and there are still a lot of small ones and pleasant buns that do not deserve separate points ( structural highlighting of the code , spellchecking , color selection in the code , smart brackets , visualization of deep debugging, and another 100500 other features ).

    Finally


    I remember a couple of years ago I really liked when the guys from our IDE team made Friction Free a mode of operation that allows you to flexibly customize CodeRush specifically for your coding style. This was done specifically to minimize the impact of the assistant’s artificial intelligence, namely, so that he doesn’t think that he knows better than you, that he likes and dislikes him, and does not add incomprehensible pieces of code in response to accidental keystrokes on the keyboard. Specifically, this “silent mode” shows confirmation if, during typing, you ran some CodeRush command:



    Those. if you liked what happened, then you can let him do this further. So over time, just by doing your usual work, you can teach CodeRush to do only what you need, and not interfere with the usual coding process (a few years ago, he really sinned this), without breaking your habits, that, as you know, is one of the signs of software that is nice to use. I remember when this opportunity first appeared, I specifically set this mode and was able to get rid of several annoying chips of this "wise guy", which were sometimes accidentally called up, but which I did not have enough spirit and time to find in the settings and chop off.

    It may also be interesting:


    CodeRush for Visual Studio (product page with full features and a link to download the trial version)
    Search and Navigation Tips / Tricks with Visual Studio (article about standard IDE features from Scott Guthrie's blog)
    Beware of productivity tools (hot discussion on Habr)
    DevExpress CodeRush Tips & Tricks (a private blog about application of the tool)
    Articles about CodeRush on Habr

    Sincerely,
    Denis

    PS


    1. I am not a member of the IDE team that develops this product, although I am currently sitting on the same floor. Therefore, I ask you to consider this post only as a personal opinion of the average CodeRush user. The official position of the IDE team or statistics on TOP features may not coincide with mine. This post arose spontaneously as a result of loyalty to this product and the presence of a couple of free days for the New Year holidays.
    2. If one of the readers also uses CodeRush, then I ask, so to speak, to exchange experiences, and share your favorite lists of product chips (or even its analogues) in the comments. It so happened that after the 3rd year of the institute (where, by the way, Visual Assist dabbled), I immediately got into DevExpress, where I became very attached to CodeRush, and as a result, I did not look deeply at any other similar tools. I would be glad to learn another experience and maybe even adopt something for myself, although they say that the choice of IDE productivity tools is done only once in a lifetime ...

    Only registered users can participate in the survey. Please come in.

    What CodeRush features do you like?

    • 13.7% 1. Collapse the project tree in Solution Explorer 8
    • 12% 2. Quick file navigation in solution 7
    • 10.3% 3. Quick navigation by type and member in solution 6
    • 15.5% 4. Navigation by type and member use 9
    • 17.2% 5. Namespace Optimization 10
    • 24.1% 6. Code Analysis and Formatting 14
    • 20.6% 7. Removing a type into a file, renaming a type or file 12
    • 13.7% 8. Adding base type constructors 8
    • 25.8% 9. Removal of a method or variable 15
    • 25.8% 10. Templates for quick code generation 15
    • 6.8% Other (I will tell in comments) 4
    • 56.8% None (I will answer why in the comments) 33

    Also popular now: