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:
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 (
internal), you can choose different types of code to generate (
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.
The same thing is applicable while generating methods. Have a look into that.