New CodeRush Plugin – CR_ImportNamespace

Problem 1: Have you ever started writing code, and then realised you were using a Type directly, without importing it’s namespace?

You could fix this by either fully qualifying the Type in place, or moving to the top of the file, adding an imports or using statement (referencing the appropriate namespace) and then finally working out where you were before you moved, and returning there.

This takes you away from your code, and context switches you away from the problem you were trying to solve. This costs you time and therefore money (and often sanity)

Note: With CodeRush, dropping a Marker [Alt+Home] before you move to the top of the file, will greatly ease the return journey [Esc].

Problem 2: Have you ever gone a stage further, and used a Type without even referencing it’s assembly?

This time it’s even worse… You have to switch your focus out of the editor entirely, and use … *gulp* … the “Add Reference” dialog.

Nooooooooooooooooooo!

The Add Reference dialog

I don’t know anyone who likes to use the ‘Add Reference’ dialog. I’ve heard it referred to as perhaps the most annoying part of visual studio. Others claim it’s the 2nd most annoying. beaten in this case to the top position, by “Accidentally hitting F1. both of these are seen in this light, because of the ridiculous amount of time that they can eat up.

The Add Reference dialog is slow and awkward and it takes you away from your code. It has several tabs that might help you in various situations, but 99% of the time these tabs are just not useful to me.

The Project Tab: Is very quick to load but is limited to the projects in your solution. This can be handy, but most of the time the references I need are not a part of my solution.

The Browse Tab: Works well also, but really it’s something of a last resort. Navigating directory structures looking for the assembly you want can be long and drawn out, and the fact that often you are returning to the same 2-3 locations makes it feel very repetitive.

The Recent Tab: Is comparable to the Projects tab. It is quick to load, but does not appear to list enough assemblies to be particularly useful. I work with a fair breadth of assemblies, which means that they cycle through the Recent Tab quite fast. I can’t honestly say that I visit the recent Tab with any real hope of finding the assembly I need.

The .Net Tab: Is the tab I find myself using more than every other, and it’s what makes me dread this dialog. The first time I choose to pick a reference from this tab in any given session, it takes around 30 seconds to fill and become responsive again. 30 seconds? Are you kidding me? Seriously?

Hmmmm … if only there was a way to avoid the Add Reference dialog……

Oh Wait..

Introducing CR_ImportNamespace

CR_ImportNamespace is designed to allow you to add namespace and assembly references without ever leaving the editor. It functions as a CodeProvider. Which is to say that the functionality is accessed through the Code menu on the CodeRush smart Tag.

Availability

The “Import Namespace…” code provider is made available when your caret is on an undeclared type.

For example:

ImportNamespaceNoCacheYet

The first time you trigger the “Import Namespace…” CodeProvider, the plugin will create a cache of all the types in the version of the .Net framework, which your current project targets. This cache will be referred to during subsequent invocations.

ImportNamespaceBuildingCache

Once this cache is built, you will be presented with a list of namespaces which contain a matching type:

ImportNamespaceAction

If only one namespace contains such a type, then this namespace will be automatically chosen after the cache is completed.

On subsequent invocations, if only a single namespace is applicable, then it will be offered as a top level menu item:

ImportNamespaceSingleChoice

If more than one namespace is suited to the task, then each of these will be presented as a submenu:

ImportNamespaceMultiChoice

However no matter how the namespaces are presented to you, the selection of one will produce the same effect.

  • - The namespace is imported.
  • - Any required Assembly is referenced.
  • … and you never move away from your existing code.
  • Finally unlike other implementations, CR_ImportNamespace is not limited to finding and referencing projects within your solution, or even to assemblies referenced by them. It covers the entire framework versions 2.0, 3.0, 3.5 and 4.0 . It understands different framework profiles (client and full) and will only offer up namespaces suited to your current project.

So where can you get this glorious new plugin? Do you have to wait for the next release of CodeRush? Do you have to wait for 2012? No, as ever, we’re committed to accelerating your productivity whenever we can. In this case… Now

Yes that’s right no. This plugin and it’s accompanying source has been generously donated to our favourite community project. You can find the relevant links and details here

  • So let’s stop messing around, manually adding namespace and assembly references. Let’s get on with the business of writing code to solve business problems, and see what develops.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.