Search code examples
visual-studio-2008code-formattingautomatic-properties

Is there a way to get Visual Studio 2008 to stop formatting my AutoProperties?


In Visual Studio 2008's Options > Text Editor > C# > Formatting, I have the following settings ticked.

  • Automatically format completed statement on ;

  • Automatically format completed block on }

This is really helpful for when I'm writing a method or a for/foreach/while/if statement.

ie if I write

void MyMethod(){}

I want it to reformat it to the following when I type the last }

void MyMethod()
{
}

However, when I write:

bool MyProperty { get; set; }

I want it to stay that way instead of getting changed to:

bool MyProperty 
{ 
    get; 
    set; 
}

Is there anyway that I can get this to happen or am I dreaming? The only way I can think of is turning those two settings off....but that just results in the annoyance getting shifted to when I write methods and if statements etc.

Update: Just thought I'd mention that I use Resharper...so if there's a way to accomplish it through there I would be interested in knowing that too.


Solution

  • Awesome! I managed to figure it out. Thanks to Anton I had a closer look at the settings available in Resharper and I was able to figure something out.

    My solution involves a combination of settings in Resharper and VS2008.

    In VS2008, I turn off Automatically format completed statement on ;

    I then turn on the setting in Resharper for IntelliSense Completion Behavior to Automatically insert parentheses after completion.

    This allows me to type:

    bool MyProperty {
    

    To get:

    bool MyProperty {}
    

    Which then allows me to add the get; and set; lines without them formatting...