Code Cleanup


ReSharper 4.0 introduces Code Cleanup — an extended feature set that supersedes Reformat Code.

Compared to Reformat Code, Code Cleanup provides two significant advantages:

  • You can now not only reformat code but also remove code redundancies, reorder type members, migrate to C# 3.0, and perform a lot more tasks, all with one 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. 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.

to the top

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:

to the top

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:

to the top

Migrating to C# 3.0

Code Cleanup is a huge helper when you face the task of adopting new C# 3.0 practices. 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:

to the top

Reordering Type Members (C# only)

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

to the top

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 among team members.

to the top