Creating your own Visual Studio code snippets

by robotix1986 19. July 2009 11:44

So just some time back I got thinking... everytime I start reading mails in the C# discussion alias at my company or Eric Lippert's explanations in them... the first thing I do is open up my very extensively used Console Application project in Visual Studio, comment out the existing main function for future reference and start writing a new one... and it is kind of a pain to do this.. so I thought that it's time to get it automated.. so I wrote a snippet to do that for me.

Below is the code for that: -

<?

xml version="1.0" encoding="utf-8" ?>
<
CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <
CodeSnippet Format="1.0.0">
        <
Header>
            <
Title>mainfn</Title>
            <
Shortcut>mainfn</Shortcut>
            <
Description>Code snippet for 'Main' function</Description>
            <
Author>Alvaro Rahul Dias</Author>
            <
SnippetTypes>
                <
SnippetType>Expansion</SnippetType>
                <
SnippetType>SurroundsWith</SnippetType>
            </
SnippetTypes>
        </
Header>
        <
Snippet>
            <
Declarations>
                <
Literal>
                    <
ID>expression</ID>
                    <
ToolTip>Code in main method</ToolTip>
                    <
Default>Console.WriteLine("Hello World!");</Default>
                </
Literal>
            </
Declarations>
            <
Code Language="csharp"><![CDATA[ public class MyClass
            {
                public static void Main()
                {
                    $expression$
                    $selected$ $end$
                }
            }
]]>
            </
Code>
        </
Snippet>
    </
CodeSnippet>
</
CodeSnippets>


Most of the fields above are self explanatory. I'll explain a few important ones.
The <Shortcut> tag specifies what you need to type in VS to use this snippet.
<SnippetTypes> - where you can use this snippet, Expansion, Surround With or both.
<Code Language="csharp"> - the actual code to be inserted

Interesting thing to note is that all the variable items are marked with $ signs. The $selected$ attribute signifies where the selected code should go in case you use this code as a sorround with snippet.
The $end$ attribute signifies where the cursor should go once you're finished with the snippet.

Hope the above helps in your coding adventures.


Regards,
AlD

Tags: , ,

.NET

Comments

10/10/2009 12:00:18 AM #

Blocked Drain

I have been experimenting with the express editions of Visual Studio to develop my knowledge for a number of months and  am starting to make the conversion to the professional edition. In advance of this I would like to improve my  knowledge of using the tool before I spend real money. My earlier experience is as a web coder with php, mysql, most linux based tools and a little flash, now I am moving to a Microsoft package. I am finding it is a large learning curve and am attempting to build my awareness with some  blog reading.  The phrase " Creating your own Visual Studio code snippets " in your post got me aroused my curiosity.  I feel the Visual Studio tutorial web sites  are oftentimes inflexible and mention the identical items looking like an online manual.  Dialog in blogs often cover actual ways to overcome issues that takes me through the learning curve more quickly.  Thanks for the note.

Blocked Drain United Kingdom | Reply

10/11/2009 8:52:37 PM #

cash advance

I never thought of that this way .. good writing.

cash advance United States | Reply

10/15/2009 5:04:29 PM #

no teletrack payday loans

Interesting information. May I add this blog to my linkexchange directory ?

no teletrack payday loans United States | Reply

10/22/2009 12:44:02 PM #

robotix1986

sure... go ahead... glad all of you liked this post

@david.. that's true... coz a lot of people blog when they face issues and/or overcome them

robotix1986 India | Reply

12/1/2009 1:09:10 AM #

payday loans

thanks!  very helpful post!! like the template btw ;)

payday loans United States | Reply

12/17/2009 11:10:31 AM #

anonymous proxy

Great insights. I loved to read your article. You must be putting a lot of time into your blog!

anonymous proxy Thailand | Reply

12/18/2009 5:42:50 AM #

Hirephpdevelopers

There are Applications project in Visual Studio.Nice informative guideline  

Hirephpdevelopers United States | Reply

12/18/2009 9:05:10 AM #

proxy

Great share. Keep up the good work.

proxy Thailand | Reply

12/18/2009 7:50:56 PM #

Skin care

Your post give me some idea. Thank you.

Skin care Thailand | Reply

12/18/2009 10:15:46 PM #

Camera lense

Excellent post.

Camera lense | Reply

12/18/2009 11:13:49 PM #

Digital camera

Great post. I like it.

Digital camera United States | Reply

12/22/2009 11:41:14 AM #

ผลบอล

This is a very nice post.

ผลบอล Thailand | Reply

12/23/2009 1:58:13 AM #

unblock myspace

Great blog, this could be the best blog I ever visited thi month. Never stop to write something useful dude!.

unblock myspace | Reply

12/25/2009 1:54:34 AM #

Gamefly

Its an amazing post .I had been searching for the information from long time thanks for the post.

Gamefly United States | Reply

12/25/2009 1:59:26 AM #

Payday Loans

I was looking for this information since a long time. You have really fininshed my search by posting this here. It will proven to be very beneficial for me

Payday Loans United States | Reply

12/25/2009 3:13:00 AM #

paydayloans

I like what I see. keep it going

paydayloans United States | Reply

12/29/2009 6:21:56 PM #

Ggler

Nice post. I love it.

Ggler United States | Reply

1/7/2010 9:56:46 AM #

zygor guides

You may have not intended to do so, but I think you have managed to express the state of mind that a lot of people are in. The sense of wanting to help, but not knowing how or where, is something a lot of us are going through.

zygor guides United States | Reply

1/8/2010 9:51:12 PM #

Mobilt bredbånd

There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game.

Mobilt bredbånd United States | Reply

1/10/2010 7:18:24 AM #

feline behavior

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.

feline behavior United States | Reply

1/14/2010 12:35:20 AM #

offshore havens

Well, this is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!

offshore havens United States | Reply

1/16/2010 6:48:27 AM #

airsoft guns

Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information.

airsoft guns United States | Reply

1/16/2010 2:45:30 PM #

stock loan

Valuable information and excellent design you got here! I would like to thank you for sharing your thoughts and time into the stuff you post!! Thumbs up

stock loan United States | Reply

1/24/2010 6:33:25 AM #

cash advance

is that all you can say about this ? hmm ..

cash advance United States | Reply

1/24/2010 7:39:30 AM #

nine west ankle boots

Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!

nine west ankle boots United States | Reply

1/31/2010 12:01:38 AM #

cash loans

For success, attitude is equally as important as ability.

cash loans United States | Reply

1/31/2010 7:28:14 AM #

contractor accountant

This is a really good read for me, Must admit that you are one of the best bloggers I ever saw.Thanks for posting this informative article.

contractor accountant United States | Reply

2/2/2010 12:43:43 AM #

beyerdynamic dt 880 headphones

This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article

beyerdynamic dt 880 headphones United States | Reply

2/3/2010 12:28:50 PM #

ekstern backup

There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game.

ekstern backup United States | Reply

2/4/2010 2:27:02 PM #

payday loans

There is joy in work. There is no happiness except in the realization that we have accomplished something.

payday loans United States | Reply

2/6/2010 10:01:18 AM #

online payday loans

There is joy in work. There is no happiness except in the realization that we have accomplished something.

online payday loans United States | Reply

2/7/2010 3:19:35 AM #

how to get rid of fat

Hi. this is kind of an "unconventional" question , but have other visitors asked you how get the menu bar to look like you've got it? I also have a blog and am really looking to alter around the theme, however am scared to death to mess with it for fear of the search engines punishing me. I am very new to all of this ...so i am just not positive exactly how to try to to it all yet. I'll just keep working on it one day at a time.

how to get rid of fat United States | Reply

2/7/2010 4:19:25 AM #

fast payday loans

Do not go where the path may lead, go instead where there is no path and leave a trail.

fast payday loans United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About robotix1986

Yet another software developer in the software industry writing some kewl code and exploring new technologies when not doing the routine work stuff.

RecentComments

Comment RSS
Software Blogs - BlogCatalog Blog Directory