Visual Studio 2015现在将成员移动到新行

时间:2015-12-03 22:42:38

标签: c# visual-studio-2015 code-formatting

当我们需要为属性使用支持字段时,我们有一种将支持字段与其所属属性相结合的做法:

public int MyProperty
{
    get { return _MyProperty; }
    set { _MyProperty = value; }
} private int _MyProperty;

出于多种原因,我们更倾向于在顶部列出一长串成员变量。

  1. 你不必向上和向下滚动,你可以在那里看到它。
  2. 删除属性时,变量不会留在重构上。
  3. 复制和粘贴时,你永远不会忘记带成员变量。
  4. 问题:

    当我们按Ctrl E + D或选择编辑|时,Visual Studio现在将成员变量移动到下一行高级|格式文档。

    public int MyProperty
    {
        get { return _MyProperty; }
        set { _MyProperty = value; }
    } 
    private int _MyProperty;
    

    我玩过工具|选项|文字编辑器| C#|格式化|新行部分。

    任何人都知道如何让visual studio停止将成员变量移动到新行?

    仅供参考,我有Resharper。

2 个答案:

答案 0 :(得分:0)

我认为此选项可能会给您带来问题:

enter image description here

启用Leave statements and members declaration on the same line

答案 1 :(得分:-2)

或(当然)

public int MyProperty { get; set; }

是这些天的首选风格(语法糖,相同的结束代码)。