23

我最近升级到 R# 7.1,我遇到了这个问题,该To Property With Backing Field操作取代了我的支持字段并将它们移动到类的顶部。

例子:

第 1 步:定义自动属性:

public class MyClass
{
    //... Lots of members here

    public int MyNewProperty {get;set;} // <- Create auto Property
}

第 2 步:ReSharper 的“To Property With Backing Field”

在此处输入图像描述

预期结果:

public class MyClass
{
    //... Lots of members here

    private int _myNewProperty; // <- Backing field immediately above property
    public int MyNewProperty 
    {
       get
       {
           return _myNewProperty;
       }
       set
       {
           _myNewProperty = value;
       }
    }
}

获得的结果:

public class MyClass
{
    private int _myNewProperty; // <- Backing field on top of the class

    //... Lots of members here


    public int MyNewProperty 
    {
       get
       {
           return _myNewProperty;
       }
       set
       {
           _myNewProperty = value;
       }
    }
}

我已经Type Members Layout通过评论“实例字段”部分来玩配置,如下所示:

<!--instance fields-->
<!--<Entry>
       <Match>
            <And>
               <Kind Is="field"/>
               <Not>
                   <Static/>
               </Not>
            </And>
       </Match>
       <Sort>
           <Readonly/>
           <Name/>
       </Sort>
    </Entry>-->

但我仍然得到相同的行为。

问:如何防止这种行为并将其恢复到 V6.X 版本?

4

1 回答 1

10

是 JetBrains 开发人员的俄语评论。本文专门介绍 R# 8 版本。他说,在开始时将私有字段放在一起比将其放在财产附近更常见。他建议在他们的反馈系统中开票。此外,他说他们可能会在 8.1 版本中引入这样的设置。
简而言之,现在不可能。

于 2013-07-25T14:36:25.443 回答