Tim Hibbard

CEO for EnGraph software
posts - 628 , comments - 1632 , trackbacks - 459

My Links

News



Add to Google

Twitter












Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

EnGraph Blogs

Links

Other

Roll

VS 2008 - I want my prop snippet back!

For those of us that implement INotifyPropertyChanged on our state objects, the new Automatic Properties feature of Visual Studio 2008 hasn't been very useful.  In fact, the snippet prop that used to create a private variable and associated public property has now been replaced by an Automatic Property.

Thanks to a comment by SnYnE on this blog post, there is an easy way to get the functionality back.

Simply create a new text file at:
C:\users\*your user name*\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets

Call it "propc.snippet"

Populate the contents with:

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

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

<CodeSnippet Format="1.0.0">

<Header>

<Title>prop</Title>

<Shortcut>propc</Shortcut>

<Description>Code snippet for property and backing field</Description>

<Author>Microsoft Corporation</Author>

<SnippetTypes>

<SnippetType>Expansion</SnippetType>

</SnippetTypes>

</Header>

<Snippet>

<Declarations>

<Literal>

<ID>type</ID>

<ToolTip>Property type</ToolTip>

<Default>int</Default>

</Literal>

<Literal>

<ID>property</ID>

<ToolTip>Property name</ToolTip>

<Default>MyProperty</Default>

</Literal>

<Literal>

<ID>field</ID>

<ToolTip>The variable backing this property</ToolTip>

<Default>myVar</Default>

</Literal>

</Declarations>

<Code Language="csharp"><![CDATA[private $type$ $field$;

public $type$ $property$

{

get { return $field$;}

set { $field$ = value;}

}

$end$]]>

</Code>

</Snippet>

</CodeSnippet>

</CodeSnippets>

Now when you type "propc" in Visual Studio, you will get the property constructor that you are used to.

 

Print | posted on Friday, February 8, 2008 1:58 PM | Filed Under [ .NET ]

Feedback

Gravatar

# re: VS 2008 - I want my prop snippet back!

Excellent! Just what I was looking for. Why did MS get rid of this??
10/15/2009 9:37 AM | James
Gravatar

# re: VS 2008 - I want my prop snippet back!

thanks a lot!!
1/27/2010 3:31 AM | Rudi
Gravatar

# re: VS 2008 - I want my prop snippet back!

Thank a lot.
11/19/2010 5:51 AM | xda
Gravatar

# re: VS 2008 - I want my prop snippet back!

Reading old post to figure out it this is for me.
12/9/2010 4:23 AM | Avaliacao de Imoveis BH
Gravatar

# re: VS 2008 - I want my prop snippet back!

Thanks dude. Your cool.
6/23/2011 3:43 PM | Dave
Gravatar

# re: VS 2008 - I want my prop snippet back!

FYI, this was added back into VS 2010 as 'propfull'
1/7/2012 1:36 PM | Jonathon
Gravatar

# re: VS 2008 - I want my prop snippet back!

Thanks a lot for your effort
10/28/2012 8:22 AM | Robert
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: