A Handy Refactoring with CodeRush (InLine Temp)

I’ve recently started using CodeRush with Visual Studio 2010 and am so far very impressed with the convenience it adds to coding.  One thing that is very clear is that the creators of CodeRush are real programmers and look very hard for patterns that us developers are constantly doing.  As I run into these things that get my attention, I plan on blogging them.  Some are just earth shattering, and others, just nice to have.  This particular one is a nice to have.

So, say you have code like this:


var sessionAttendeeOds = 
new SessionAttendeeODS();
listSessionAttendees =

When I first wrote code, I often do it like this thinking that I may have more methods I’m going to call against the instantiated object.  In this case, many years later, I’m looking at the code and want to condense it.  With CodeRush, it show me three little dots under the variable sessionAttendeeOds as follows.  When I click on these three dots, I get the following screen.


When I chose “InlineTemp”, the code changes to the following, make it easier to read.

listSessionAttendees = 
new SessionAttendeeODS().GetByUsername(Context.User.Identity.Name);

Again, this is not a huge deal, but small fixes like this will add up over time and make my code cleaner and more readable.  CodeRush makes it so easy that I’m sure I’ll do this kind of thing more and more.


About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP since 2007. In addition, he's a multi-course video author at Pluralsight. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


  1. yes mallorca, now I see what you mean. I often create intermediate variables just to keep things simple and then later put them back without having to use intermediate. I don’t think it matters performance wise. I hope the c# compiler takes care of that for us.

  2. listSessionAttendees = SessionAttendeeODS().GetByUsername(Context.User.Identity.Name);

    doesn’t this work in C#? I remember I did something like this a few times.

  3. Hi Mallorca, can you give an example?

  4. yes, but you can populate the list yourself right from the beginning, you don’t have to create that var only for creating an instance of the object.

  5. how about CodeRush vs ReSharper


Get every new post delivered to your Inbox

Join other followers: