Fostering development process in .Net

14 07 2014

Fostering development process in .Net

In this article I will explain how to speed up the development process using few fabulous features of Visual Studio IDE.

Code Snippets

What is it?

Have you ever tried writing try, foreach, while or any other keyword and than hitting tab after it. Do it and you will define what Code Snippet is and will realize what it can do.

Code Snippet is nothing but a predefined set of code that is plugged into the surface area by using a shortcut key defined for it.

When to use?

A set of code with a constant pattern but variable custom literals can be translated to code snippets. Example

for (int i = 0; i < length; i++)


The structure of for statement remains same but the variables used inside it needs to be changed. In the above code i and length would be replaced by the some other variable inline with your code. So whenever you have such kind of code that needs to be plugged in really quickly you can create a snippet for that.

How to use?

Snippets are basically and XML based files with .snippet extension. It contains two major sections Header and Snippet.

Header : This section includes the details regarding the snippet that is being used. Some details like Title of the snippet, Shortcut key for the snippet, author name and snippet type are defined in this section.

Snippet : This is the section where in the actual magic of creating the snippet is defined.

It includes other four subsections viz

  • Code Defines the language type for the snippet and the code to be plugged in.  is used for the actual code to be inserted when the snippet is used. Literals to be replaced are prefixed and suffixed by $ sign.
  • Declarations Defines the literals that need to be replaced. This appears green in color in the surface are. One can define the tooltip, default value etc pertaining to the literals in this section.
  • Import Defines the namespaces that will be automatically included if your snippet is used.
  • References Defines the dll to be included for the namespace added using Import statement

Below steps will drive you through the process of creating a sample snippet.

Step 1

Create file with .snippet extensions with below xml

Step 2

Open Visual Studio and click Ctrl+k b. This will open Code Snippet Manager window.

Step 3

Click Import and browse through the file created in step 1 and Click Ok

Step 4

Now Choose the location where in you want to categories your snippet and click ok.

If you choose Visual C# than the file would be copied to /%Visual Studio%/ VC#\Snippets\1033\Visual C# folder

Step 5

Go to the code are where in you want to use your code snippet and type replace and than hit tab key.


Code Block

What is it?

If you do not want to go by the approach of code snippets, than you can quickly achieve the same functionality by Code Blocks. Code Blocks are nothing but a predefined code that needs to be used with some refactoring.

How to use?

Creating the code blocks is simply a drag drop process.

Step 1

Select the code that you want to reuse.

Step 2

Drop it onto the toolbar. Visual Studio will create the toolbar item for the block you have copied. Rename the block to meaningful name.

Step 3

Now wherever you want to plug in the code just click on the block.


Enjoy and Speed up your development.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: