ReSharper

Code Cleanup

ReSharper provides Code Cleanup — an extended feature set that combines code formatting with removal of redundant code and applying team coding conventions.

With Code Cleanup, you can not only reformat code but also remove code redundancies, reorder type members, migrate to recent versions of C#, and perform a lot more tasks, all with a single shortcut: Ctrl+Alt+F. That means, you can save a myriad of "go-to-next-highlight-then-apply-a-quick-fix" iterations by simply running Code Cleanup!

Two default profiles — Full Cleanup and Reformat Code — can be complemented by your custom task-specific profiles.

Code Formatting

ReSharper can reformat an arbitrary selected block of code, all code in the current file, all files in a directory, or even in the entire project or solution, according to your Code Style preferences. ReSharper provides distinct formatting options for C#, VB.NET, JavaScript, CSS and XML code. Reformatting affects braces layout, blank lines, line wrapping and line breaks, spaces in various contexts, indentation, aligning multiple constructs, and a lot more options that you can fine-tune in the ReSharper Options dialog box.

To reformat the code in the current file, simply press Ctrl+Alt+F, select Reformat Code in Available profiles, and click Run.

Optimizing Namespace Import Directives

To make your code more readable, you can remove redundant using directives from your C# and VB.NET code files. With ReSharper, this tedious process is reduced to a few simple actions. Press Ctrl+Alt+F, click Edit Profiles to create a new Code Cleanup profile, select Optimize 'using' directives (or Optimize 'import' directives for VB.NET) in the list of cleanup options, and apply the profile by clicking Run in the Code Cleanup dialog box:

Removing Code Redundancies (C# only)

After ReSharper has analyzed your code, it knows pretty well where there's an empty constructor, a redundant delegate creation expression, or an 'else' keyword that is not required at all. Overall, ReSharper can remove about 30 redundancies automatically, without asking for your approval every time. To do that, press Ctrl+Alt+F, click Edit Profiles to create a new Code Cleanup profile, select Remove code redundancies in the list of cleanup options, and apply the profile by clicking Run in the Code Cleanup dialog box:

Migrating to Newer Versions of C#

Code Cleanup is a huge helper when you face the task of adopting code constructs introduced in C# 3.0. Specifically, it helps switch to auto-properties, and use 'var' in local variables and iterators according to specific rules. To migrate to C# 3.0, press Ctrl+Alt+F, click Edit Profiles to create a new Code Cleanup profile, select Use auto-property, if possible and configure using 'var' in declarations. Having done that, apply the new profile by clicking Run in the Code Cleanup dialog box:

Reordering Type Members (C# only)

In C# code, ReSharper can automatically reorder type members in your code files according to a default or custom XML pattern:

Code Style Configuration and Sharing

With more than 60 options, you can fully customize the way ReSharper reformats your code when it expands templates, completes and generates code, inserts delimiters, or when you run code reformatting as a separate action.

All style settings can be easily shared between team members.

Note:

All keyboard shortcuts provided in the "Features" section are taken from ReSharper 2.x / IDEA keyboard scheme. For details on ReSharper's two default keymaps, see Documentation and Demos.