Importing Namespace References for Extension Methods in CodeRush for Visual Studio

23 March 2011

From feature request to binary delivery in less than four hours. Here’s the timeline:

At 10:06 this morning, Apeoholic tweets the following question:

Is there a way to get #CodeRush to suggest namespace usages for extension methods?

Which led to the following discussion with one of our CodeRush devs on IM:

[10:08] Mark: Hey Alex, I have this question in a tweet -- "Is there a way to get #CodeRush to suggest namespace usages for extension methods?"
[10:09] Alex: Hi Mark, I'm not sure what he means…
[10:10] Mark: I think he's talking about adding namespace imports when an extension method is at the caret.
[10:10] Mark: I'm wondering if VS fails to do this.
[10:10] Alex: I suppose VS does it, doesn’t it?
[10:10] Mark: Check it for me.
[10:12] Alex: OK, VS fails to do this.
[10:13] Alex: And we don't have such feature
[10:13] Mark: Can we write this as a plug-in?
[10:13] Alex: Of course, but this will take time.
[10:14] Mark: What's the challenging part of this?
[10:14] Alex: Find and resolve all the extension methods
[10:15] Mark: Create a spike -- work on this for an hour and see what you get.
[10:15] Mark: Then send me that source and I can finish it up
[10:15] Alex: ok
[10:15] Mark: Then I'll have Rory put it on the community site.
[10:15] Alex: k

Which led to the development of the feature, testing, a few changes, and then this IM with Rory Becker:

[13:06] Mark: I had Alex create a plug-in spike for a feature request to add missing namespace references for extension methods (something VS does not do)
[13:06] Rory: cool
[13:06] Mark: I'm going to send this to you. Can you get this on the community plug-in site today?
[13:06] Rory: yeah sure, no problem

At 14:05, we published the feature on the community site.

Here’s the feature in action:

AddNamespaceReference

Here’s the link to the feature on the CodeRush community plug-ins site: http://code.google.com/p/dxcorecommunityplugins/wiki/CR_ExtensionMethodsHelper

We are likely to roll this functionality into a future version of CodeRush. If you have a CodeRush question or feature request, we want to hear from you. Post a comment below or include “#CodeRush” in your tweets and we’ll respond in a timely manner.

11 comment(s)
Ralf Warnat

Quick, quicker, DevExpress ... thx for sharing

24 March, 2011
Tomas Juricek 3443

Absolutely fantastic! I have missed this in Visual Studio so much! Thanks!

24 March, 2011
dk_nls

Nice!

Now what i miss sooo is auto discover the missing reference to the assembly reference - System.Configuration

When starting a new project and trying to read from the config like:

var myConnection = ConfigurationManager.ConnectionStrings["MyConnectionString"];

I would be so happy to see an auto discover of the missing system.configuration reference :)

25 March, 2011
Thomas Wieser

Nice Plugin, but it seems to have some "bugs".

Resolving Extension-Methods which are an overload, are not resolved.

Microsoft.Practices.Unity has a lot of them.

In Base there are the normal function, and as an extension the generic variants of them.

It would be nice if this works too.

30 March, 2011
Mark Miller (DevExpress)

Hi Thomas,

I've had two devs look at this and neither can reproduce. Can you send more details to support@devexpress.com?

31 March, 2011
Myles Penlington

Would love some support of MS StyleCop e.g. Coderush functions that format code to the MS StyleCop standard e.g. things around spacing of method parameters (), ":"  etc. Also cool would be reordering of methods and properties to meet the StyleCop standard.

6 April, 2011
Mark Miller (DevExpress)

Hi Myles,

Great suggestion. We're looking into it.

6 April, 2011
Mike Hanson

Can't get this to work with FluentAssertions fluentassertions.codeplex.com.

Plugin is definitely iinstalled as it shows up in Code Modification catalog and is enabled but does not work with the many extension methods of FluentAssertions, which is a real shame because I use this in every test I write

19 April, 2011
Ivan Zlatev

Doesn't work for me either.

24 January, 2012
Francois Nel

Why is this still not part of the core product?! I think allot of people would use it if the plugin starts by default.

P.S. I'm getting the following error when using the plugin in version 13.1 of DXCore:

Type: System.NullReferenceException

Message: Object reference not set to an instance of an object.

Source: CR_ExtensionMethodsHelper

Target: System.Collections.IEnumerable GetProjectSymbols()

Call Stack:

  at CR_ExtensionMethodsHelper.PlugIn1.GetProjectSymbols()

  at CR_ExtensionMethodsHelper.PlugIn1.cpAddReference_CheckAvailability(Object sender, CheckContentAvailabilityEventArgs ea)

  at DevExpress.CodeRush.Core.ContentProvider.OnCheckAvailability(CheckContentAvailabilityEventArgs ea)

29 May, 2014
Mark Miller (DevExpress)

Hi Francois,

Rory tells me the null ref exception has been fixed.

17 June, 2014

Please login or register to post comments.