Archive

Posts Tagged ‘Code Snippet’

The Snippy tool for my own snippets

April 14, 2010 Leave a comment

 

What to do?

Let us to make a snippet called “propb” which generates next final code.

01

Download the Snippy and Run it.

You can make your own code snippets using the Snippy which provides visual configurations of your own code snippets.

Download the source at http://www.codeplex.com/snippy and build the solution. This is the Snippy application screen.

021

Fill the Base Section.

Fill the Title, Shortcut, Author and Description. Shortcut is important key to use later this snippet.

03

Set the Literals and objects section.

In our “propb” snippet, we would add 3 objects of type,property and pmember. This is the list after adding them.

04

Click the Add button and fill the forms. This is a sample for a object addition.

05

Write the snippet code in to the code area.

Change ‘Language’ to csharp and type the code. You should mark a previous Object like ‘pmember’  with ‘$…$’ string. Also you can mark ending focus section writing ‘$end$ string.

06

Yes!. We’ve finished editing in the Snippy tool.

Write the snippet code in to the code area.

Save to the ‘My Code Snippets’ directory path.

07

Save the snippet with ‘propb’ file name to the My Code Snippets under the Windows my documents.

08

It is easy to check it in your Visual Studio Snippets Manager. Go to the Tools > Code Snippets Manager.

09

Use the snippet we made.

10

Advertisements

Visual Studio Code Snippet

April 14, 2010 1 comment

 

What is the Code Snippet?

Code snippets provide faster code generation with developer’s input options. Visual Studio supports various code snippets for C#,VB,XML and so on.

Checking Code Snippets in Visual Studio

You can check installed snippets in Visual Studio easily. Open Visual Studio > Tools > Code Snippets Manager.

001.location of code snippets manager

Navigate to the installed snippets in the Snippets Manager. You can see the information and locations of many snippets.

002.code snippets manager

These are installed snippets on my Visual Studio 2008.

003.installed snippets

Selecting C# snippets in the Visual Studio.

OK. Let us start to use a snippet for practice. We will use the “prob” snippet to generate private property with getter and setter. In the C# editor, type the start characters of “prop” and you can see the list of similar snippets. After selecting, press the TAB key twice.

004.typing snippet shortcut

The “int” and “MyProperty” strings with background color are the objects waiting your customizations. You can navigate objects in this snippet using TAB key.

005.navigate

Filling C# snippets.

Write some start words you want. If there are matched object type, you can see candidate list. Select and press TAB to fill.

006.value input

If you finish filling objects in the snippet, press ENTER key to exit.

007.finish