Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2388

New CodeRush Plugin – Cleanup File and Namespaces

$
0
0

This plugin wraps up 2 existing tasks (The ‘CleanupFile’ command and the ‘Optimize Namespace References’) in to a single new command ‘CleanupFileAndNamespaces’.

In order to use this plugin:

Step 0 – Requirements

This plugin requires version 13.2 of CodeRush and a non-express version of Visual Studio version 2010 or higher.
If you have a current CodeRush subscription, you can download the latest version through our download centre.
If not, you can download a 30 day trial of all of our .Net products, including CodeRush.

Step 1 – Download

This plugin is hosted on GitHub and is available as either VSIX or as Sourcecode

VISX_CleanupFileAndNamespaceCleanupFileAndNamespacesSourceCode

Step 2- Install

If you have downloaded the source, you will have to compile the plugin yourself, and then install from the VISX which the compile process creates.

Once you have the VISX, (via download or compilation) simply double click it, and follow the prompts.

CleanupFileAndNamespacesInstaller

Step 3 - Configuration

All that is necessary to configure this plugin, is to assign a key to the new ‘CleanupFileandNamespaces’ command.

This is done via the Shortcuts options page.

  • To open the options screen either choose DevExpress\CodeRush\Options from the main menu, or use the Ctrl+Shift+Alt+O shortcut.
    To locate the shortcuts options page, locate the IDE\Shortcuts item in the tree on the left, or use the ShortcutsPageIcon icon in the upper right of the options screen.
  • CleanupFileAndNamespacesNewShortcut  Create a new shortcut by right clicking in an appropriate folder and choosing ‘New Keyboard Shortcut’ or ‘New Mouse Shortcut’.
  • CleanupFileAndNamespacesShortcutKeysThen choose a suitable key or mouse combination based on your preferences and previous choice. I usually pick Ctrl+T for testing purposes.

 

 

CleanupFileAndNamespacesCommand Next choose the ‘CleanupFileAndNamespaces‘ command from the commands dropdown.

Finally you should set the context of this command to make it only available when you are within a .vb or .cs file. CleanupFileAndNamespacesContext

Finally click OK to accept your changes.

Create a new shortcut and assign it to the the ‘CleanupFileAndNamespaces’ command.

Step 4 – Usage

  • Place your caret in any .cs or .vb file. and invoke using the configured shortcut. CodeRush will run the ‘Optimize Namespace References’ refactoring and follow that by running any configured Code Clean operations.

For example:

The following is a fresh C# Library project, with a single unused variable declared.

SimpleClassLibraryWithUnusedDeclaration

Assuming that you have the default settings for Code Cleanup, and you trigger CleanupFileAndNamespaces from this start position, CodeRush will remove the unused using directive and the unused declaration:

SimpleClassLibraryWithUnusedDeclarationAfterCleanup

This simple plugin links together 2 often used features so that they can operate as one.

In my next post I’ll explain how this plugin works in detail.


Viewing all articles
Browse latest Browse all 2388

Trending Articles