Code Snippets: Again with the code snippets

Well the space aliens were asking me about code snippets again, and they were curious if they had to create a separate file for each of the code snippets and put them in the same folder, or could they put them all in the same file.  Then again, if you think that these space aliens might be able cross interstellar space, and haven't invited something better than C# or Java, something must be wrong.  If you are thinking that, then keep coming back to this or my other blogs as I will explain how the space aliens manage to cross space, but have less technology than the Earth.  Now back to code snippets...

 

In an earlier episode, I had shown you how to create code snippets for use in C# Express, this was required as most of the existing instructions that I can find only talk about how to create code snippets in VS Pro, VSTS.  These full versions of Visual Studio have a project type that will create XML files for you, C# Express 2005 does not have a separate project setting for XML files.  So I pointed out that you could use Notepad and create an XML file using a template that I provided.  Here is that template again:

<CodeSnippets xmlns="https://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

<CodeSnippet Format="1.0.0">

<Header>

                <Title>

                                     ADD TITLE HERE THIS WILL APPEAR IN THE CODE SNIPPET INSERTION MENU

                         </Title>

          </Header>

         <Snippet>

                        <Code Language="CSharp">

                        <![CDATA[

                                          ADD CODE HERE, COPY AND PASTE FROM YOUR CODE

                                         ]]>

                        </Code>

           </Snippet>

<Header>

                <Title>

                                     ADD TITLE HERE THIS WILL APPEAR IN THE CODE SNIPPET INSERTION MENU

                         </Title>

          </Header>

         <Snippet>

                        <Code Language="CSharp">

                        <![CDATA[

                                          ADD CODE HERE, COPY AND PASTE FROM YOUR CODE

                                         ]]>

                        </Code>

           </Snippet>

</CodeSnippet>

</CodeSnippets>

Pretty simple, code snippets do other cool things as well that can make you much more productive and help you share code with co-workers or other people on the web.  Remember though, if you are working for a corporation or doing research for a school, sharing code with the public might not be allowed, always make sure it is ok to do so if you are working for someone.