Click here to Skip to main content
15,884,388 members
Articles / Visual Studio
Tip/Trick

Tips & Tricks: Faster Code Generation in Visual Studio 2010

Rate me:
Please Sign up or sign in to vote.
4.20/5 (4 votes)
7 May 2010CPOL2 min read 13.1K   4   3
Faster code generation in Visual Studio 2010

Before discussing this feature with you, let me ask you a question “Are you using TDD, i.e., Test Driven Development?”. If so, you will not only find this feature useful but very much attractive. So, what is that? Wait, let's ask ourselves another question “How to write code while doing Test Driven Development?”. Thinking? Right, you have to implement the skeleton of the class & methods first and then you have to write the Unit Test cases to implement the actual logic. VS2010 came up with the excellent feature of generating codes for you. Have a look at the following snapshot:

image

As you can see, I don’t have a class named “Person” in my project and hence it is marking it as UNKNOWN by highlighting it in Red. If you look into the first snapshot in depth, you can find out that though the class is not present in my namespace or even in the project, it is creating the class reference in the intellisense. Great, right? Wait a minute. If you now place your cursor on top of “Person” and press F10 while holding down ALT+Shift, you will see a dropdown comes up on the screen with two menu items asking you to either generate the class for you or generate a new type.

You can find the first option easy. If you chose that, it will generate a class file named “Person” for you in the project. Let's go for the second choice where you will get more options & will find it much more interesting. This will open up a new dialog “Generate New Type” for you. There, you can choose which access modifier you need (private/public/protected/internal), you can choose different types of code to generate (enum/class/struct/interface), you can also modify the location of the class file. You can either put it in the same project or you can choose a different project available in the solution. Not only that, you can also create a new file for the class or append the class in another file. In short, this feature gives you various options to customize.

image

The same thing is applicable while generating methods. Have a look into that.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India

Kunal Chowdhury is a former Microsoft "Windows Platform Development" MVP (Most Valuable Professional, 2010 - 2018), a Codeproject Mentor, Speaker in various Microsoft events, Author, passionate Blogger and a Senior Technical Lead by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows app development. He posts his findings, articles, tutorials in his technical blog (www.kunal-chowdhury.com) and CodeProject.


Books authored:


Connect with Kunal on:





Comments and Discussions

 
GeneralReason for my vote of 3 simple Pin
Luyen Ha16-Dec-10 21:29
Luyen Ha16-Dec-10 21:29 
QuestionHow did I miss this? Pin
Doug Hackerott18-Aug-10 19:22
Doug Hackerott18-Aug-10 19:22 
AnswerRe: How did I miss this? Pin
Kunal Chowdhury «IN»19-Aug-10 6:33
professionalKunal Chowdhury «IN»19-Aug-10 6:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.