www.codeguru.com/cpp/v-s/devstudio_macros/codegeneration/article.php/c10793/

Back to Article

Home >> Visual C++ / C++ >> Visual Studio >> Add-ins & Macros >> Code Generation


Introducing Visual Studio 2005 IntelliSense Code Snippets
Rating:

Patrick Gallucci (view profile)
October 20, 2005

Go to page: Prev  1  2  3  

On the left side of the dialog window, click the checkbox next to "My Code Snippets" and click the Finish button (see Figure 14).


(continued)



Figure 14: Click the Checkbox Next to "My Code Snippets" and Click Finish

You now can open the "My Code Snippets" node and highlight the c3header snippet (see Figure 15). This will show some of the general attributes that you assigned to the snippet in the XML file.

Figure 15: Open the "My Code Snippets" Node and Highlight the c3header Snippet

Now, you can go to a C# class file and test out your new snippet. Figure 16 shows the output.

Figure 16: Output from Testing Out Your New Snippet

It may not seem like a lot, but the fact that you can type the shortcut and insert your own header is only the beginning of what you will be able to do.

Even though that was not a lot of steps, the fact that you dealt with raw XML might be a little more than you want to handle. So, the next two sections show you how I mass-produce my snippets, as well as an open source project that allows you to create and test your snippets.

Snippet Macro

I found myself creating code snippets for a lot of the same methods that I was overriding. So, I created a Visual Studio Macro to create a snippet out of the code that I selected. Download the macro and the test project. Load the macro in Visual Studio, and then highlight the code out of which you want to create a snippet (see Figure 17).

Figure 17: Highlight the Code Out of Which You Want to Create a Snippet

From the macro explorer, double-click the CreateSnippet macro (see Figure 18).

Figure 18: Double Click the CreateSnippet Macro

The screen will wiggle, and then you will have the output in a new file in the solution explorer. The file content from what you selected above will look like Figure 19.


(Full Size Image)

Figure 19: The File Content from Your Selections

It's still a little raw, but you should be able to create your own templates to help generate snippets pretty quickly.

Visual Basic Code Snippet Editor

The open source project I mentioned at the end of the previous section is the Visual Basic Code Snippet Editor, a tool that enables you to create, edit, and test your code snippets. Take the time to download the Visual Studio 2005 edition from the GotDotNet Workspace. The enhancements from the Beta 2 version are well worth it. It is still not completed, but the team working on this is doing a great job. Figure 20 shows a screen shot.


(Full Size Image)

Figure 20: Screenshot of Visual Basic Code Snippet Editor

Your Own Snippet Library

Take the Visual Basic Code Snippet Editor for a spin and try some of the tips in this article and the Visual Studio 2005 BOL. You will have a nice library of your own snippets in no time. I hope this tutorial gets you to explore the new features of IntelliSense code snippet technology in Visual Studio 2005.

About the Author
Patrick Gallucci is a Senior Consultant in the Communications Sector at Microsoft. He has more than thirteen years experience in information technology. Patrick's area of focus is developing operational efficiencies using development tools and technologies such as .NET, SQL Server, BizTalk Server, Content Management Server, and Commerce Server. His certifications include MCSE, MCDBA, and MCT. Patrick is a recent instructor of MSF Design, Microsoft C#, ASP.NET, and other .NET classes.

Go to page: Prev  1  2  3  

Downloads

  • CodeSnippetsLibrary.zip - Download source code - 54 Kb

    Tools:
    Add www.codeguru.com to your favorites
    Add www.codeguru.com to your browser search box
    IE 7 | Firefox 2.0 | Firefox 1.5.x
    Receive news via our XML/RSS feed








  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    IBM Whitepaper: Innovative Collaboration to Advance Your Business
    Internet.com eBook: Real Life Rails
    Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
    Internet.com eBook: The Pros and Cons of Outsourcing
    Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
    Internet.com eBook: Best Practices for Developing a Web Site
    IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
    Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
    Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
    IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
    Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
    Go Parallel Article: Getting Started with TBB on Windows
    HP eBook: Storage Networking , Part 1
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
    HP Video: Is Your Data Center Ready for a Real World Disaster?
    Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
    HP On Demand Webcast: Virtualization in Action
    Go Parallel Video: Performance and Threading Tools for Game Developers
    Rackspace Hosting Center: Customer Videos
    Intel vPro Developer Virtual Bootcamp
    HP Disaster-Proof Solutions eSeminar
    HP On Demand Webcast: Discover the Benefits of Virtualization
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Microsoft Download: Silverlight 2 Software Development Kit Beta 2
    30-Day Trial: SPAMfighter Exchange Module
    Red Gate Download: SQL Toolbelt
    Iron Speed Designer Application Generator
    Microsoft Download: Silverlight 2 Beta 2 Runtime
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
    Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
    Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES