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