2

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.

Mihai Limbășan
  • 64,368
  • 4
  • 48
  • 59
mezoid
  • 28,090
  • 37
  • 107
  • 148

3 Answers3

3

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.

Sandeep Datta
  • 28,607
  • 15
  • 70
  • 90
  • I'm using VS2008 too... but I'm also using Resharper which seems to be part of the problem. – mezoid Feb 12 '09 at 07:49
2

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

Community
  • 1
  • 1
mezoid
  • 28,090
  • 37
  • 107
  • 148
1

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

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288