Auto Code Snippets in Visual Studio 2008

Background:

Visual Studio 2008 makes life very easy for a developer. We can have complete code blocks created automatically. This is at a very advanced level for VB.NET and is still evolving for C#.

More Details:

Right Click and select “Insert Snippet” from the context menu [Or] use Ctrl + K + X and you will see a menu which lists all available options which are neatly grouped.

Just for a sample, I used the insert Snippet to create a code block to “Call the ExecuteReader Method of a SQLCommand” – the following lines were produced automatically:

Dim reader As SqlDataReader

      Dim previousConnectionState As ConnectionState = conn.State

      Try

          If conn.State = ConnectionState.Closed Then

              conn.Open()

          End If

          reader = cmd.ExecuteReader()

          Using reader

              While reader.Read

                  ' Process SprocResults datareader here.

                  Console.WriteLine(reader.GetValue(0))

              End While

          End Using

      Finally

          If previousConnectionState = ConnectionState.Closed Then

              conn.Close()

          End If

      End Try

Some available snippets are listed below:

For C# Code Behind Files

C#:

if, Region, Checked, Class, Else, Enum, for, foreach, if, indexer, try, while, Etc.

Workflow:

DependencyProperty Event handler & property.

For VB.NET Code Behind Files

This is a programmer’s delight. The list is very exhaustive. Some samples below:

Code patterns like if, if else, try Catch, property.

Data - ADO.NET - Create a parameterized SELECT Command, Execturereader, Etc.

Data - LINQ - From..Select, From..Order By...Select, Etc.

Collections and Arrays, FileSystems, Math

Office Development

Connectivity, Crystal Reports, Security, Workflow

Smart Devices

Windows Forms – Drawing, Etc

Logging

WPF

The list is almost endless. See it to believe it…

Statutory Warning!

The use of this feature may lead to code that is NOT in synch with the coding standard on naming conventions of your project/team. So take care of this point.

Happy programming!

150 150 Burnignorance | Where Minds Meet And Sparks Fly!