views:

355

answers:

3

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.

+1  A: 

ReSharper might have such feature, though I'm not absolutely sure.

Anton Gogolev
I do use Resharper too...so even suggestions for doing it that way would help
mezoid
In VS, ReSharper menu item - Options - C# Formatting Style in the leftmost treeview, see what it's got there.
Anton Gogolev
+3  A: 

Are you sure this is a problem in VS2008? Because my auto properties stay put...

given...

bool MyProperty { get; set; }

it stays as ...

bool MyProperty { get; set; }

Even after I apply the format selection command.

Note: I have the same VS formatting options selected as you. Though I am using VS2008 SP1.

SDX2000
Mine stay put too
Ray
I'm using VS2008 too... but I'm also using Resharper which seems to be part of the problem.
mezoid
+2  A: 

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...

mezoid