【问题标题】:ReSharper 7.1 "To Property with Backing Field" Moving fields out of placeReSharper 7.1“到带有支持字段的属性”将字段移出原位
【发布时间】:2013-07-19 21:29:41
【问题描述】:

我最近升级到 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 版本?

【问题讨论】:

  • 我没有 ReSharper,所以我无法测试,但是如果你从 &lt;Sort&gt; 标签中删除 &lt;Name/&gt; 会发生什么?
  • @newStackExchangeInstance 整件事都被注释掉了。我以为这样可以解决问题,但没有
  • 尝试取消注释并这样做,看看会发生什么。
  • @newStackExchangeInstance 刚试过。相同的行为 =(
  • 我感受到了你的痛苦,虽然我只是适应并继续前进。 V8 现在可用,也许它将作为设置。

标签: c# visual-studio-2010 resharper-7.1


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-05-06
  • 2021-12-13
  • 1970-01-01
  • 2012-03-27
  • 2017-04-26
  • 2019-02-03
  • 1970-01-01
  • 2015-06-22
相关资源
最近更新 更多