Visual Studio 2010 provides a nifty little feature which let’s you generate code from within the editor. In this post I will show you how to use this feature. Imagine that you are having a fantastic coding day and you are coding at 100mph. You have just realised that you need a class called car and you want to do it ninja style. Just type in this.

image

Visual studio displays Car in red because it cannot find a Type named Car. Put your cursor on Car and hit Ctrl + .

image

The smart tag gives you two options:

  1. Generate class for ‘Car’
  2. Generate new type…

If you select the first option, a new class is created for you in a new file and appropriately named Car.

The second option which is “Generate new type…” gives you more control over the code which will be generated.

image

In the dialog box you can choose Access (public or private) and you can also select if you’d like to generate a class, struct, interface or an enum. An option also exists down below to either add the newly generated code to an existing file or create a new file.

Pretty neat I think.

Tagged with:
 

One Response to Visual Studio 2010 Code Generation With Intellisense

  1. Mark says:

    yeah that’s neat, another little time saver….”Add to existing File” shouldn’t be an option though :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>