ReSharper 7.1 “To Property with Backing Field” Moving fields out of place

瘦欲@ 提交于 2019-12-03 16:07:25

问题


I've recently upgraded to R# 7.1 and I'm having this problem where the To Property With Backing Field action displaces my backing fields and moves them to the top of the class.

Example:

Step 1: Define an auto property:

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

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

Step 2: ReSharper's "To Property With Backing Field"

Expected result:

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

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

Obtained Result:

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;
       }
    }
}

I've already been playing with Type Members Layout configuration by commenting the "instance fields" part, like this:

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

But I still get the same behavior.

Q: How can I prevent this behavior and revert it to the V6.X one?


回答1:


Here is the comment in Russian from JetBrains developer. The article is devoted to R# 8 release. He said that placing private fields together at the beginning is much more common use case than placing it near property. He advised to open ticket in their feedback system. Moreover, he said that maybe they introduce such setting in version 8.1.
In short, it is not possible now.



来源:https://stackoverflow.com/questions/17755809/resharper-7-1-to-property-with-backing-field-moving-fields-out-of-place

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!