Freigeben über


vs 2005 code snippets part 2

the schema for the code snippet format is well documented and easy to read. I have put a copy here, (snippetformat.xsd) as the first thing you need to do is get familiar with the schema, then making changes become trivial. I will then demonstrate automating the creation of snippets based on the schema and using a visual studio macro.

 

So the easiest thing to show is just how easy it is create and then make substitutions in the snippet that highlights the changes that you are expected to make. So We will start with creating a file header for your source code file. The following two images show the output we are trying to achieve.

 

-c# file header info-

 

-vb file header info-

 

now instead of locating this in another file and copy/paste into a new, we can simply create an inteli-sense code snippet that makes this available anywhere in our code. we will then extend this existing one to add some features that will make it clear how this can start to save you lots of time while you are coding. the first thing that I did was to create a template for my snippets. you will see later on how this has evolved into many templates for different types.

 

below is the template we will use for our file info snippet.

 

Generic C# Snippet Template

 

So we will make a few changes and see how to use this in our own code.

 

i changed the title, author description and added some declarations to be substituted in the snippet. I also saved my file as fileinfo.snippet.

 

change 1

 

we will now add declarations for the substitutions in our code snippet. these will all be literal snippets, but we will dive into the more powerful objects later on. we will add declarations for the file name, summary, date and author. for each we will give an id, tooltip and a default value.

 

 

in the next part we will complete this snippet.

 

 

 

patrickgallucci