Built in Code Snippets can usually be found at a location similar to:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#\if.snippet
For this blog, you will need to use one of the existing snippets, the file extension is *.snippet.
In this discussion I am going to use the “if” snippet, which has the following XML
First change the filename, you don’t want to change this file, temporily, I am changing mine to:
- C:\Users\yourname\Documents\Visual Studio 2010\Projects\Snippet\variables.snippet
Using the snippet file above I changed it to the following and after making the change I placed it in the folder:
- C:\Users\sstokes\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets
Once everything is working, you will be able to do the following, select pvariable (the code snippet name) then press tab twice
You get the following placed in your code:
Pretty easy. If you have issues with the code entered make sure you stripped out all of the old code from the snippet you used as a “template”. Generally keep all of the other items, change the Author from Microsoft to your name. Play around with this feature, which could do with a little more videos and explanation. from Microsoft. Oops, I am a Microsoft employee, but I meant the development team. However, if you use existing snippets as starting points then you shouldn’t have any big issues. Just make sure to save your snippet to the C# My code snippet folder or VB My code snippet folder, also there is one for XML, which come to think of it is quite useful. There are no code snippets for VC++, sadly.
Well have fun.