Share via


New IDE Features in Visual Studio 2010 for C# Developers

After a quick review of C# language features, let’s do the same for the IDE improvements. So, what’s in there for C# developers?

Generate From Usage

This feature greatly improves Visual Studio support for test-driven development (TDD). However, it is useful even if you don’t use TDD at all. It might increase your productivity by simply reducing the number of keystrokes and eliminating repetitive typing. For example, now I can write code like this:

class Program
{
    static void Main(string[] args)
    {
        var test = new SampleClass(firstParameter: "test", secondParameter: 0);
        test.FirstProperty = 1;
        test.SampleField = 2;
        int value = test.SomeMethod(100);
    }
}

SampleClass doesn’t exist at this moment, so everything is going to be highlighted as an error. But instead of typing all the declarations, I set the cursor on the highlighted error, press CTRL + “.” and have the IDE generate code for me.

image

Visual Studio 2010 can generate classes, constructors, properties, fields, enum members, and methods (and it uses the names of optional parameters from the constructor or method calls). Just look at how much code I didn’t have to write. All this was generated by simply pressing CTRL + “.” several times.

class SampleClass
{
    private string firstParameter;
    private int secondParameter;
    public int SampleField;

    public SampleClass(string firstParameter, int secondParameter)
    {
        // TODO: Complete member initialization
        this.firstParameter = firstParameter;
        this.secondParameter = secondParameter;
    }

    public int FirstProperty { get; set; }

    internal int SomeMethod(int p)
    {
        throw new NotImplementedException();
    }
}

However, sometimes IntelliSense, which is so nice when you’re dealing with already-defined classes, may get in your way when you try this “generate from usage” approach. For example, suppose that I want to add another property to SampleClass and call it First. Since I already defined FirstProperty, IntelliSense autocompletes First to FirstProperty when I type “=”.

To avoid this problem, press CTRL+ALT+SPACEBAR to switch to IntelliSense suggestion mode (as opposed to completion mode). In suggestion mode, IntelliSense is less aggressive – it doesn’t autocomplete member names after you type an equal sign or open parenthesis or something like that. But you are still able to choose an existing member from a list if you need to complete the member name.

image

Check out Generate From Usage and List Members topics on MSDN to learn all the details about this feature.

Call Hierarchy

The new Call Hierarchy window helps you analyze your code and navigate within it. I opened one of the LINQ sample projects that come with Visual Studio. (Click Help and then Samples on the Visual Studio menu to get the list of samples.) I chose the WebServiceLinqProvider sample, since it’s a fairly big one.

Now, to open the Call Hierarchy window, I can put the cursor on any method, property, field, indexer, or constructor, no matter whether it’s a declaration or an actual call, right-click it then and click View Call Hierarchy (or press CTRL+ALT+K). Call Hierarchy is also available if you right-click a member in the Object Browser or in Class View.

image

For me, the biggest advantage of this window is that under the Call To node you can see which members call the selected member, and where those members are. This information is often hard to get and analyze, since member calls are usually scattered across the project.

In the same window, under the Calls From node, you can also see which members the selected member calls. For virtual and abstract members, you can see the overrides.

What’s cool is that you can navigate from this window to the code you want to look at in more than one way. First of all, you can see what the method call looks like in the Call Sites column. You can also see the name of the file that contains this code.

image

Second, you can double-click any method call and Visual Studio will open the method for you.

But if you want to still see the method you are analyzing, there’s third way. Open the Code Definition window and move it so you can also see the code editor and the Call Hierarchy window. (The best place would be a second monitor, and this is now easy to do with all these undockable windows, thanks to the new WPF UI.) Now if you click on a method call (instead of double-clicking), you can see the corresponding code in the Code Definition window, without losing your position in the main editor.

Don’t forget to check out the shortcut menu, which allows you to use such commands as Go To Definition, Find All References, and Add as New Root for each member.

Speaking of navigation improvements, the next cool IDE feature is a quick search tool for symbols. Just press CTRL + “,” (or click Edit and then Navigate To) to see the new Navigate To window. You can search for types, members, and files in this window. Camel-case search is supported as well. Everything is displayed in one result list. In the following screenshot, you can see a class, a constructor, and a file whose capital letters match my search request. And it goes without saying that you can navigate to any item with a simple double-click.

image

Reference Highlighting

This is one of those subtle features that just make things better. If you put the cursor on a symbol (method, property, variable, etc.), all instances of this symbol are automatically highlighted in the code editor. You can also navigate from one instance to another within a file by pressing CTRL+SHIFT+UP/DOWN ARROW. How to: Use Reference Highlighting on MSDN describes how you can configure the highlighting color and turn on/off the feature (it’s turned on by default).

image

Box Selection and Multiline Editing

Suppose that you want to change several fields in your class from public to private. And you have a couple dozen of those. Now you change the declaration by typing public just once. Press ALT and then use your mouse or arrow keys to select the box area (in my case, the column that contains the private keywords).

image

Now simply type the new text and it will be repeated on each line. Check out this nice video from the Visual Studio Editor team, which shows more scenarios where this feature may come in handy (adding comments, writing repetitive code, etc.).

Docking Windows and Zoom

I already mentioned that moving Visual Studio to WPF helped to improve multiple-monitor support. In fact, you can undock any window and rearrange everything according to your needs. Dock windows to the edges of the main window, or simply leave them in the middle of the screen if you want.

Another useful feature enabled by WPF is zooming. Press CTRL and use your mouse wheel to enlarge or decrease your font size. The C# team does a lot of presentations, and I can tell you that it’s much easier to give (and see) a demo now.

Extension Manager

If you’re still looking for ways to improve your IDE, try one of the numerous add-ins developed by the community and other companies. In this release, Visual Studio greatly improved its SDK for add-in developers. Also new is the Extension Manager, which helps you to easily download, install, and uninstall Visual Studio extensions. You can get to it by clicking Tools and then Extension Manager.

Now you can search for add-ins online without leaving the IDE. The Extension Manager checks for add-ins and their updates at Visual Studio Code Gallery.

image

What Else?

No, this is not all that’s in there for you. I just mentioned the most popular features that might be useful to any C# developer, no matter what technology or API you use.

There are a lot of subtle improvements that might be hard to notice. For example, error highlighting now works in more places. Another example is IntelliSense, which now supports camel casing and filtering in all of its lists.

Also, a lot of enhancements are specific to certain technologies: Office development, WPF, Silverlight, SharePoint – just to name a few. I also didn’t mention improvements in the debugger or application lifecycle management .

Instead of providing tons of links, I’ll provide just one: Visual Studio 2010 Product Highlights. This document briefly describes major Visual Studio improvements and provides all necessary links to relevant MSDN docs.

P.S.

Special thanks to Kirill Osenkov, Alan Berman, and Mick Alberts for reviewing, editing, and providing helpful comments.

Comments

  • Anonymous
    May 10, 2010
    Very nice... VS2010 is a rocks solid IDE. Thanks for the post. Very helpful. -A

  • Anonymous
    May 11, 2010
    I created a new Console Application in VS 2010 Professional with 4.0 Framework selected.  Then I typed the four lines you have above into the Mail method.  When I clicked Generate Class on SampleClass, however, I get a new SampleClass.cs file that only has: class SampleClass { } And I immediately have several errors including SampleClass does not contain a constructor that takes 2 arguments. What am I missing here?

  • Anonymous
    May 11, 2010
    Nevermind, I figured it out.  I didn't catch the "generated by simply pressing CTRL + “.” several times" on the first read through. So it isn't actually looking at how the class is being used when generating the class (which was what I thought from the name Generate From Usage).  This is just an expansion of the Generate Method to include classes, constructors, and properties.

  • Anonymous
    May 12, 2010
    The comment has been removed

  • Anonymous
    May 12, 2010
    After a decade at last we got column selection feature in VS IDE :)

  • Anonymous
    May 12, 2010
    Good to see that some of the features that have previously been provided by third party plugins are making their way to becoming standard features of the Visual Studio IDE. A productivity boost for everyone.

  • Anonymous
    May 12, 2010
    Hi boss, the Column selection and auto-generate type are already there is VS2008 ;-) I suppose it’s not the new feature in VS2010

  • Anonymous
    May 12, 2010
    Column selection has been in the VS .NET IDEs since the start and in Visual C++ since at least VC++ 5.0. However, it has been enhanced in VS 2010.

  • Anonymous
    May 13, 2010
    Quite impressive, especially "Generate from usage" and "Navigate To" features! Well, JetBrains ReSharper users (and me among them) have been enjoying such tools for years now. However, once in a while I am in a situation where ReSharper is not available, e.g. pair programming with somebody on the project not using it. These new VS features will be a good help for me on such occasions..

  • Anonymous
    May 13, 2010
    The comment has been removed

  • Anonymous
    May 13, 2010
    "Hi boss, the Column selection and auto-generate type are already there is VS2008 ;-)" There was column selection but without mulitline editing.

  • Anonymous
    May 13, 2010
    Can call hiearchy be extended to find

  • public methods that can be made private (i.e., callled from within the same class)
  • public methods called by only one other class (i.e., could be moved from existing class to the other class and made private)
  • Unused methods, member variables, classes, constants
  • Classes that are used by only one other class which could be nested within that class
  • File level call hiearchy to find objects in files that are called by cde in only other other file (i.e., merge the two files together)
  • Classes having no member variables which have non-static methods (that could be made static).
  • Class level call hiearchy showing classes called only by classes in another project (i.e., so that the class in project A could be move to project B since project B is the only user of that class)
  • Projects unreferenced by any code outside of that project (i.e., all classes in a project are not called or used by any other class.  This would let the entire project be removed from the solution). These all involve finding an simplifying the structure of a class, project and entire solution so that each object, project and solution has access to only the most minimal set of things outside of itself. This also leads to simplification of the entire application solution by reducing the entire code base into a single project solution with a minimal number of source code files. This technique is commonly used used by mainframe and C embedded systems developers when working with large code bases.
  • Anonymous
    May 13, 2010
    Thanks Very Nice Post,Keep Post More

  • Anonymous
    May 27, 2010
    Thanks  for this wonderful post,  the pictures are self-explanatory and language is vibrant and goes in the flow. In all, beautiful article. I expect more article from you in the upcoming sessions. -Harshit

  • Anonymous
    June 13, 2010
    new IDE features to generate codes for classes,constructors etc. is a very very intelligent feature thanks a lot

  • Anonymous
    June 17, 2010
    Wow code generation, about any tool (e.g. Visual Assist, Resharper, etc) provide this feature since Visual Studio 6. Nice to see how microsoft managed to adapt this feature in the short interval of over 10 years of development. Btw: this also matches to those "new" navigation features...

  • Anonymous
    June 18, 2010
    The comment has been removed

  • Anonymous
    July 14, 2010
    I agree with Alexandra about features migrating into the IDE. There's also the situation where some workplaces ban the use of thirdparty plugins or people feel uneasy about using them due to bad experiences where they made the IDE unstable. Thanks for a great post that has only accelerated my desire to work regularly in VS2010.

  • Anonymous
    July 25, 2010
    In the DevStudio 2010, when I do a find, and I click on one of the results (or "Go to Location" in the context menu), the C# code file opens in the small window below, where the Find Results is, NOT in the large window above, where the other code files are. How can I change this behaviour? Thanx, Joan

  • Anonymous
    October 07, 2010
    Thanx ,good tutorial.......... Can u describe more details with examples .

  • Anonymous
    January 19, 2011
    Vs2010 removed the 'Promote local variable to parameter' feature - recfactoring is no longer allowed.

  • Anonymous
    January 19, 2011
    First thing I did was remove the new font from the editor and change the background colours back to classic style of VS2008.  Why they ruined a good ide - I don't know.

  • Anonymous
    February 09, 2011
    The comment has been removed

  • Anonymous
    May 10, 2011
    Very nice article to know .Net framework 4.0 major improvements visit : www.dotnetcodes.com/.../Articles-55-Net-framework-40-major-improvements.aspx

  • Anonymous
    January 23, 2012
    In VS 2008 to close an open document window within the editor one would click a button on the top r.h.s but in VS 2010 the close button has been moved to the tab which is hosting the document. I wonder you can provide both options in vs 2010.

  • Anonymous
    January 23, 2012
    Majid, you can get such VS 2008 behavior on VS 2010 with Pro Power Tools, which includes Tab Well UI extension (see visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef).