XNA Using Statements

If you’re anything like me constantly having to re-add the XNA using statements each time you create a new class can be more than tiresome.  To remedy this I finally decided to dive into the world of Visual Studio code snippets.  The first thing I immediately learned is that I have been missing out!  So many doors of increased productivity have been opened, so I’m sure that I’ll be throwing a lot of snippets up here in the future for your consumption.

Anyway, I created two snippets to automate referencing the XNA namespaces that we all use.  The first one only includes the most common XNA namespaces, namely:

  • Microsoft.Xna.Framework
  • Microsoft.Xna.Framework.Content
  • Microsoft.Xna.Framework.Graphics
  • Microsoft.Xna.Framework.Input

It is available through the snippet shortcut of ‘xnausing’.

The second, longer, snippet includes ALL Microsoft.Xna.* namespaces.  It is available through the snippet shortcut of ‘xnausingall’.

You can download them here.

If you’ve never used or installed code snippets before, read on for a visual guide.

First, unzip the downloaded archive to any convenient location.  I tend to just use my desktop.

Now, open up Visual Studio C# Express, and find your Tool menu on the menu strip.  Find the option for Code Snippets Manager…, and click.

You’ll see a new window open up.  This is your Code Snippets Manager where you can add a new folder/category of snippets, remove the same, or import snippets from single files.  For this example, we’ll be using the latter, so find Import… in the bottom left of the window, and click.

The usual open file dialog will appear, and you’ll want to navigate to where you unzipped the downloaded archive.  Select one or both snippets and click Open.

You’ll be taken back to the Code Snippets Manager where you will find that the My Code Snippets folder is now populated by our two new snippets.  Click OK and go back to the main Visual Studio window.  To test our snippets, we’re going to create a new Windows Game project in the usual way.  In the below example, I just deleted the already-created using statements at the top of the file.

Now, type ‘xna’ and you’ll see IntelliSense, in it’s infinite wisdom, find our two snippets: xnausing, and xnausingall.

Now tab twice, and the IDE will select the ‘xnausing’ snippet and complete the code for you.  You should see the proper using statements completed for your, and you’re good to go!

Share This:
  • RSS
  • Twitter
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • email
  • Print
This entry was posted in C#, XNA and tagged , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked with an *.

*
*

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>