Using Generate from Usage

Tips Search

If you like the tips then you'll love the book!

Order your copy today:
http://www.amazon.com/gp/product/0735649928

Using Generate from Usage

  • Comments 5

Menu:  Edit -> IntelliSense -> Generate -> New Type
Command:  Edit.GenerateNewType; EditorContextMenus.CodeWindow.Generate.GenerateNewType
Versions:  2010
Published:  1/21/2010
Code:  vstipEdit0011

 

I'm a big fan of Test Driven Development (TDD) so I absolutely love this tip as it is a big step toward enabling the TDD folks in Visual Studio.  The idea behind it is simple, it allows you to use classes and members before you define them.  There are some slight differences between the C# and VB implementations so let's take a look:

VB

  1. Start by using a class that you haven't created yet:

    image

  2. Obviously, you will get an error.

    image

  3. But wait.  When you click the Error Correction Options you get something new:

     image
  4. Click on "Generate 'Class Dollar' " and you get a new file called Dollar.vb with a class stub inside:

    image
  5. The error is gone and you are ready to start using the class.  You basically repeat the process for members that you create for the new class as you use them.

 

C#

  1. Start by using a class that doesn't exist:

    image
  2. Here you have a couple of options.  You can right-click and choose Generate -> Class or you can click on the Smart Tag and choose "Generate class for 'Dollar' ".  They both do the same thing and I show both options here:

    image

    image
  3. You get a new file called Dollar.cs with a class stub inside:

    image
  4. The error is gone and you are ready to start using the class.  You basically repeat the process for members that you create for the new class as you use them.

 

 

SPECIAL NOTE:  Once you get the hang of this and actually start using this feature for TDD activities you will NOT use the examples I gave but will instead choose the "Generate New Type" option.  The dialog is the same for VB and C# and looks like this:

image

 

Notice you have the ability to set Access, Kind, and-most importantly, Location.  It's the Location option that TDD folks will use to put the classes into the proper project outside of their test project.

  • Hi!

    Thanks for all tips so far!

    Also glad to see tha I now can read teh whole post in Google Reader, superb!

    Keep up the good work!

  • Thanks Ulf :)

    Yeah i put down the crack pipe and finally got the RSS feed sorted out plus the great folks at MSCOM support hooked me up with fixing the comments.

    Z

  • Ditto on getting RSS working right!

  • And when will C++ get this feature?

  • Hey Ben :)

    Not sure but I would think that as each team comes up with something cool like this the other teams would evaluate it and see if it fits into their goals for the language.  I'll ping the C++ team and see if there is any timeline I can share.

    Z

Page 1 of 1 (5 items)
Leave a Comment
  • Please add 6 and 3 and type the answer here:
  • Post