Blog Moved ....

ScottCate.com

community

frenz

my book(s)

my products

Resharper: Don't Develop with out it. : Optimize Using's

Today's highlighted Resharper feature.

Optimize Using's. I love this. Love it, Love it, Love it.

A default C# code behind of an aspx page looks like this.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace myKB.CRMServer.Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

After you code against the page for awhile, you'll consume some of those "using statements", but mostly not all of them. Resharper has an auto format command with CTRL+ALT+F. That shows this dialog.

Scott Cate Resharper - File File Sample

Click reformat, and you're left with.

using System;
using System.Web.UI;

namespace myKB.CRMServer.Web
{
    public partial class WebForm1 : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

The System is there for the Parameters in the Page_Load method, and System.Web.UI is left behind, for the Page that WebForm1 is inheriting from.

Does this help any? Yes. Reflection is much faster, without having to look through all the using assemblies that aren't in reference.

Doesn't that make it harder to use objects not referenced, since they won't show up in intellisense? Oh but they can, and they will in my next blog post :)

Thanks Resharper for such a great product.

Comments

John S. said:

That was my favorite feature of ReSharper but the performance hit didn't justify keeping it installed just for cleaning up usings. I'd love to see someone else tackle this problem though.

# April 18, 2007 3:19 PM

Laurent Kempé said:

Yeah it is a good feature but there are so much on this product. I am like you I can't work without it.

# April 18, 2007 5:37 PM

SimoneB said:

Well John as far as I know Re# does much more than that. Download the keymap .pdf from its website and try a couple of keys.

# April 18, 2007 6:08 PM

Evan said:

I love that feature too, but I think my favorite has to be using Alt+Ins to generate all my properties.

Evan

# April 18, 2007 7:06 PM

Jim Arnold said:

"Reflection is much faster, without having to look through all the using assemblies that aren't in reference."

Er...how so?  Unused references are simply compiled away - they do not result in an assembly reference.  That said, you should still do it if only for code clarity!

Jim

# April 19, 2007 8:50 AM

scott cate said:

Evan, I'll show ALT+INS in a future post, that's great also.

# April 19, 2007 11:07 AM

scott cate said:

Jim Arnold, That comment is directed specifically at Intellisense using reflection. A using statement brings a namespace into scope, and Intellisense has to look at it. On a slower machine, this can make a difference.

# April 19, 2007 11:10 AM

Jim Arnold said:

Aye fair enough, I misunderstood you

# April 20, 2007 9:05 AM

Aaran said:

Apologies for going against the grain, but VS2008 lets you 'Sort and Remove' usings...

# February 26, 2008 3:57 AM