Visual Studio code snippets for creating fast and easy data sources

John Doe / Monday, May 31, 2010

If you have to reuse the same code over and over again in different projects, the Visual Studio provides a nice feature for this - "IntelliSense Code Snippets".
For example, as you all know, you can create a constructor for a class by typing "ctor" inside that class 

 This is a pretty simple code snippet, but you can expand it and create more complex ones and reuse this code within few key strokes.

How to make them :

1. Add a new File in the Visual Studio :

2. Choose an XML File and save it as a .snippet file

4. Fill the minimum required fields for a code snippet

<?xml version="1.0" encoding="utf-8"?>

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

  <CodeSnippet Format="1.0.0">

    <Header>

 

    </Header>

    <Snippet>

 

    </Snippet>

  </CodeSnippet>

</CodeSnippets>

5. Build on and create your own code snippet

Creating and Using IntelliSense Code Snippets 


How to install them :

All you need to do is copy then to your Visual Studio Code Snippets folder.It should look like this :
<drive>:\<user>\Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets
or :
<drive>:\Program Files (x86)\Microsoft Visual Studio X.0\VC#\Snippets\1033\Visual C#
A small pack with some frequently used code snippets (C#) you can find here : .

Edit (9/3/2010) Updated Person class with a boolean property and System.Text namespace 

1. Dependency Property

2. Attached Dependency Property

3. INotifyPropertyChanged implementation

4. Property with INotifyPropertyChanged

5. Test class with hierarchical data

6. Test class with different data types