Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

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.

 

Posted on Friday, February 8, 2008 1:58 PM .NET | Back to top


Comments on this post: VS 2008 - I want my prop snippet back!

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Excellent! Just what I was looking for. Why did MS get rid of this??
Left by James on Oct 15, 2009 9:37 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
thanks a lot!!
Left by Rudi on Jan 27, 2010 3:31 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Thank a lot.
Left by xda on Nov 19, 2010 5:51 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Reading old post to figure out it this is for me.
Left by Avaliacao de Imoveis BH on Dec 09, 2010 4:23 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Thanks dude. Your cool.
Left by Dave on Jun 23, 2011 3:43 PM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
FYI, this was added back into VS 2010 as 'propfull'
Left by Jonathon on Jan 07, 2012 1:36 PM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Thanks a lot for your effort
Left by Robert on Oct 28, 2012 8:22 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
Woow U SaveThe Day For ME dude I Love You
Left by Kalpa on Nov 07, 2013 12:50 AM

# re: VS 2008 - I want my prop snippet back!
Requesting Gravatar...
thank you you are the best
Left by MK on Nov 27, 2014 10:37 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net