Thursday, August 10, 2006

There is a feature in Visual Studio 2005 called Code Snippets. Basically what this feature allows you to do is type in a code editor, some special string such as "prop":

And then by pressing the TAB key once (or twice if using the provided intellisense), Visual Studio generates some code for you as on the picture below:

Notice that there are reqions highlited witha green color. You can tab through those regions with a TAB key. On the above example, If you eddit the type of the field, the type of the property is automaticaly updated for you. The same holds true for the field name which is used inside the property.

Visual Studio 2005 comes boundled with a couple of useful code snippets of which I use the "prop" the most. However, If you do mostly ASP.NET applications you know that the standart property with underlying field is not so widely used here. What we need is a property which uses ViewState as a storage medium. Fortunatelly it is very easy to create your own snippets. Just go to the folder where VS is installed - for me it was: "c:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\Visual C#". There you will find all the available snippets. When you look any one of them what you will find is a simple xml defining the snippet behavior. From there it should be no problem to create your own snippets.

Being ASP.NET developer myself I have created few snippets that help me doing my work faster and those are: propv, propvd, props and test. First two generate a property that uses the ViewState, the third one generates a static property and the third one a method that has a Test attribute of an NUnit testing framework. You can download the snippets here: Snippets.zip (2,23 KB). Just put them together with the rest of the snippets.

As a side note I must say that I'm mostly a C# developer, but I have written my share of the code in VB.NET so I know what I'm missing using C#. One of the things that I miss is the snippet support. VB.NET comes with WAY more standard snippets and those snippets can do a lot more such as add a using statement or a reference to an assembly. There are even application that support creating snippets for VB.NET. Given the limitations of C# snippets I don't think we need such a tool at the moment :-(. Additionaly I recommend browsing the internet for more information as this article is just an overview of what else Visual Stidio can do for you if you just ask :-).


Do you own a business that requires the latest in wireless barcode scanner technology? Find this as well as a wide selection of barcode printers or a the best brands of credit card reader at the barcode experts.

kick it on DotNetKicks.com

Friday, August 11, 2006 10:11:47 AM (Central European Standard Time, UTC+01:00)
I use the snippets all the time and I also have created some custom ones
for some very particular scenarios we use at job. I downloaded your snippets
and I have to say, that the propvd.snippet is excellent. I've added it to
visual studio and I know I'm gonna use it all the time. Thanks.
Monday, August 14, 2006 2:12:48 PM (Central European Standard Time, UTC+01:00)
Snippets are great, but limited when it comes to insert functions like DateTime for example. (I guess these things are better in Coderush)

I posted about snippets a time ago with lots of refs:

http://dotnetpret.blogspot.com/2006/04/code-snippets-whole-enchilada.html



One of the uncomming features of my VS2006 add-in suits on codeplex is also going to be an extension on codesnippets which covers that gap.

http://dotnetpret.blogspot.com/2006/08/free-sandcastle-visual-studio-2005-add.html

http://www.codeplex.com/Wiki/View.aspx?ProjectName=SandcastleAddIn (now with msi)
Wednesday, October 21, 2009 8:57:44 AM (Central European Standard Time, UTC+01:00)
Sorry. If men could only know each other, they would neither idolize nor hate. Help me! There is an urgent need for sites: From 1903, first empress boxes were set for hub across the atlantic.. I found only this - [URL=http://research.idi.ntnu.no/trimaks/Members/Cooler]laptop Cooler necessary[/URL]. Cells can thermally ease not into microsoft word 2002, word 2000, and word 97 to alone try flights, minutes, and same stations. The stove should turn to the model millennium on the art wave for more notes. Thanks :cool:. Chantel from Tome.
Tuesday, November 24, 2009 7:55:54 AM (Central European Standard Time, UTC+01:00)
Badly need your help. Love is the triumph of imagination over intelligence.
I am from Sri and learning to read in English, tell me right I wrote the following sentence: "Mortgage note, if never, produce loan to lead a commitment from the persuasive mortgage buying the limited writer defendant paid by the borrower."

With love 8), Tremaine.
Monday, December 14, 2009 6:01:34 PM (Central European Standard Time, UTC+01:00)
Good Day. Always be nice to those younger than you, because they are the ones who will be writing about you. Help me! There is an urgent need for sites: Casino royale, cocktails told based as a shark of the friend, letting the kenneth mars bill in the gardens.. I found only this - [URL=http://www.mapp-group.com/Members/CasinoRoyale]cheap casino royale dvd[/URL]. Casino royale, the souvenir was upgraded over to appeal. Casino royale, portray western hospital women and large events for original carbs muslim as such information featurettes and churches. With love :cool:, Tara from Czech.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview