DISQUS

Just Sayin' More Words: VS2005 ‘prop’ C# Code Snippet in VS2008

  • Aaron Powell · 1 year ago
    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.
  • John · 1 year ago
    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.
  • Serban · 1 year ago
    nice going mate!
  • Laurent Duveau · 1 year ago
    Nice one!

    For your information I submitted this bug on Connect some time ago:
    http://weblogs.asp.net/lduveau/archive/2008/03/...
  • Sabrina · 1 year ago
    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
  • Dmitri · 1 year ago
    Why do you have to type the name of backing field and property? Surely it is possible to have one derived from another?
  • John · 1 year ago
    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.
  • jason b · 1 year ago
    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.
  • Mizan · 10 months ago
    You can do it by setting an attribute

    [DefaultValue(false)]
    public bool SomeProperty
    {
    get;
    set;
    }
  • Jesper Eiby · 8 months ago
    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.
  • paolo · 4 months ago
    thank you for this!