【发布时间】: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,所以我无法测试,但是如果你从
<Sort>标签中删除<Name/>会发生什么? -
@newStackExchangeInstance 整件事都被注释掉了。我以为这样可以解决问题,但没有
-
尝试取消注释并这样做,看看会发生什么。
-
@newStackExchangeInstance 刚试过。相同的行为 =(
-
我感受到了你的痛苦,虽然我只是适应并继续前进。 V8 现在可用,也许它将作为设置。
标签: c# visual-studio-2010 resharper-7.1