DISQUS

DISQUS Hello! Just Sayin' More Words is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Just Sayin' More Words

A blog by John Sheehan
Jump to original thread »
Author

VS2005 ‘prop’ C# Code Snippet in VS2008

Started by John Sheehan · 10 months ago

Automatic properties are nice, but sometimes you just want a good ol’ regular property with a backing field. Visual C# 2005 had the ‘prop’ code snippet which generated this:

Visual C# 2008 now generates the following when using the ‘prop%2 ... Continue reading »

11 comments

  • Umm... why? The C# 3.0 compiler will generate valid IL from the new prop. The old one is no longer needed as it adds unnessisary lines of code.
  • For default values. For instance, if I have a string property that should always have a default, I can't do that with automatic props.
  • nice going mate!
  • Nice one!

    For your information I submitted this bug on Connect some time ago:
    http://weblogs.asp.net/lduveau/archive/2008/03/...
  • As A comment to the post, I add that the old prop snippet is a must when you are not yet using the new Framework but still use Framework 2.0 as I do.

    And I ask you a hint if you can:

    I dont' know if it's a problem in my installation of Visual Studio But today I used for the first time a snippet and When I pressed tab instead of going from the first placeholder to the second it simply inserted a tab in the placeholder variabile
    such it happened in Visual Basic 2005.
    Have you ever had such behaviour? Could it be generated from some crazy default setting?

    Sabrina
  • Why do you have to type the name of backing field and property? Surely it is possible to have one derived from another?
  • Best I can tell from the C# Code Snippet docs, you cannot transform the backing field name into the property name (or vice versa). There's very basic support for functions, and none of them cover this case.
  • Not really on topic, but I love the contrast settings you have in that screen shot...the background is black with some of the key words in orange and so forth. Can you export your settings to a file or make it available here? By the end of the day my eyes are dead tired from staring at white screens. I've tried playing with the settings, but I'm graphically challenged I guess you could say.
  • You can do it by setting an attribute

    [DefaultValue(false)]
    public bool SomeProperty
    {
    get;
    set;
    }
  • Hello, I just want to thank you for the code snippet.

    I find the new way is breaking my code routine, because it's hard to make a property that's readonly.
  • thank you for this!

Add New Comment

Returning? Login