Y'herd thisun? 

“It's better to be unofficial till you get the facts”
-Lt. Columbo

Get back the explicit prop

TaggedCoding, CSharp

Here's one of those things that some of us came cross way back and fixed on our machines and promptly forgot about, but that comes up every time you hit a new machine or machine from a new .Net convert.

A few days ago I told a friend how he could get a few performance gains by modifying the wizarded Entity classes and when I went to his house and sat at his 'puter my fingers called up the prop snippet and got that VS2008 shortie:

public int myProp{ get; set;} 

Ugh, I hate that thing. 


I know that "under the hood" C# creates a hidden variable for that syntax-saccharine shorthand but it gets me that back in the day of VB5/6 when the tool created ANYTHING under the hood all we ever heard from C++ guys was that that practice was shining example of why VB sucked... nothing should be "under the hood."

And here are the C++ folks coming into the VB RAD of C#, letting their tool do exactly the same stuff they said was so terrible.  In fact, seems to be that there are more wizards in C# and VB.Net than VBClassic ever had!

A scan of shows that I loved VBClassic in its day and back then we just had to accept some things that the tool did at its core... but given my druthers I prefer knowing what my properties are writing to.  Explicitly.

And if you do too... here's how to get the VS2005 "prop" snippet back:

1) Go into your VS 2008 snippet folder.  By default it will be  "C:\Program Files\Microsoft Visual Studio 9.0\VC#\Snippets".  Inside that folder are the installed language folders for your machine, such as 1033 for American English, go into that subfolder.

2) Inside that folder are a bunch of other ones, you want to go into the "Visual C#" subfolder.

3) Scroll down to the file "prop.snippet" rename it to be "prop08.snippet"

4) Open the prop08.snippet file with Notepad and change the <Header><Title> node value from "prop" to "prop08".

5) Make the same change to the "Shortcut" node value

6) Save the file.

7a) If you have VS2005 installed go into its "...snippets\[language code]\Visual C#"  folder and copy the prop.snippet file that's there, paste it into the VS2008"... snippets\[language]\Visual C#" folder.  Go into a projet and type prop and you should see both options, "prop" for the explicity VS2005 style and "prop08" for the hidden variable style.

7b) If you don't still have VS2005 installed, create a new text file in the "...snippets\[language]\Visual C#" folder, name it "prop.snippet".  Open it in Notepad and paste this text in:

xml version="1.0" encoding="utf-8" ?>
 <CodeSnippet Format="1.0.0">
<Description>Code snippet for property and backing field</Description>
<Author>Microsoft Corporation</Author>
<ToolTip>Property type</ToolTip>
<ToolTip>Property name</ToolTip>
<ToolTip>The variable backing this property</ToolTip>
<Code Language="csharp"><![CDATA[private $type$ $field$;
 public $type$ $property$
get { return $field$;}
set { $field$ = value;}


Save the file and type "prop" in  a project and you should see both options. 

You may have to restart Visual Studio to see the new snippet, I don't but you might have to :)

Geeze, they added all of those WPF-supporting prop snippet options... why couldn't they just leave the old one too... instead "prodding/urging/forcing" folks to get things hidden?

Robert Smith
Kirkland, WA

home     who is smith    contact smith     rss feed π
Since 1997 a place for my stuff, and it if helps you too then all the better