Did C# formatting change in Visual Studio 2015? And how can I change it back?

C#Visual Studio-2015

C# Problem Overview


In past versions of Visual Studio, I could create a single-line autoproperty in C# like this:

public int Whatever { get; set; }

If I hit Control-K, Control-D to format, the property would stay that way.

But in Visual Studio 2015 RC, when I type the property, it wraps, and even if I unwrap it, formatting wraps it again:

public int Whatever
{ get; set; }

I've noticed it with constructors as well. In the past, an empty constructor (e.g. that just called a base class constructor) could look like this:

public Whatever(int stuff)
    : base(stuff) { }

Now Visual Studio 2015 insists on doing this:

public Whatever(int stuff)
    : base(stuff)
{ }

Have others noticed this? Is this a change made in Visual Studio 2015? If so, is there a way I can change it back? I looked through the C# formatting section of Tools > Options, but couldn't find any new setting that might affect this.

(It's not impossible that one of my add-ins is causing it, but I didn't find any obvious culprits.)

(Why even care? Because when I use the Collapse to Definitions outlining command, single-line properties and constructors stay as they are, whereas wrapped ones collapse. If they're collapsed, I can't tell at a glance that they're empty; I have to toggle them to uncollapsed just to see that nothing's there.)

C# Solutions


Solution 1 - C#

Go to Tools > Options > Text editor > C# > Formatting > Wrapping

Check "Leave block on single line" and "Leave statements and member declarations on the same line"

enter image description here

Solution 2 - C#

This behavior does appear to have changed. Go to the Tools > Options menu, and then navigate to Text Editor > C# > Formatting > Wrapping.

In previous versions of Visual Studio, if you had "Leave block on single line" checked and "Leave statements and member declarations on the same line" unchecked, empty braces would stay on the same line if you put them there.

But in Visual Studio 2015 RC, if you have "Leave block on single line" checked and "Leave statements and member declarations on the same line" unchecked, the empty braces are wrapped.

You have to have both items checked to prevent the braces from wrapping. But this also has other consequences, such as leaving multiple statements on the same line...

int x = 5; int y = 3;

...which is why I never had it checked before.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRyan LundyView Question on Stackoverflow
Solution 1 - C#Oddmar DamView Answer on Stackoverflow
Solution 2 - C#Ryan LundyView Answer on Stackoverflow