2013-07-19 40 views
22

我最近已升级到R#7.1,我遇到了这个问题,其中To Property With Backing Field行动取代我的支持字段并将其移动到类的顶部。ReSharper 7.1“与财产与支持领域”移动领域不合适

实施例:

步骤1:定义一个自动特性:

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

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

步骤2:ReSharper的 “财产随着支持字段”

enter image description here

预期成果:

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?

+0

我没有ReSharper,所以我无法测试,但如果从''标签中删除'',会发生什么情况? –

+0

@newStackExchangeInstance整个事情都被注释掉了。我认为这样可以解决问题,但它没有 –

+0

尝试取消注释并做到这一点,看看会发生什么。 –

回答

9

Here是来自JetBrains开发人员的俄语评论 。这篇文章专门讨论R#8版本。他说,在一开始就将私人领域放在一起比将它放置在财产附近更为常见。他建议在他们的反馈系统中打开票。此外,他说,也许他们在8.1版中引入了这样的设置。
总之,现在是不可能的。

+0

+1 =>这真的很有用!spasibo bolshoe! –

+0

A机票已打开,目前预定为V9.1:https://youtrack.jetbrains.com/issue/RSRP-411980 – StuartQ