Visual Studio 2015 中的 C# 格式是否更改?我怎样才能把它改回来? [英] Did C# formatting change in Visual Studio 2015? And how can I change it back?

查看:18
本文介绍了Visual Studio 2015 中的 C# 格式是否更改?我怎样才能把它改回来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的 Visual Studio 版本中,我可以像这样在 C# 中创建单行自动属性:

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

public int Whatever { get; set; }

如果我按 Control-K、Control-D 进行格式化,该属性将保持不变.

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

但是在 Visual Studio 2015 RC 中,当我输入属性时,它会换行,即使我解开它,格式也会再次包装它:

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) { }

现在 Visual Studio 2015 坚持这样做:

Now Visual Studio 2015 insists on doing this:

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

其他人注意到了吗?这是在 Visual Studio 2015 中进行的更改吗?如果是这样,有什么办法可以改回来吗?我查看了工具 > 选项的 C# 格式设置部分,但找不到任何可能影响此设置的新设置.

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

(为什么还要关心?因为当我使用 Collapse to Definitions 大纲命令时,单行属性和构造函数保持原样,而包裹的属性和构造函数会折叠.如果它们折叠,我无法判断一眼就知道它们是空的;我必须将它们切换到未折叠状态才能看到那里什么都没有.)

推荐答案

转到工具">选项">文本编辑器">C#">格式">换行"

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

勾选Leave block on single line"和Leave 语句和成员声明在同一行"

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

这篇关于Visual Studio 2015 中的 C# 格式是否更改?我怎样才能把它改回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆