为什么 ReSharper 在将属性转换为自动属性时需要扫描所有文件?
访问具有支持字段的属性
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
与访问自动属性之间有什么区别吗?
public int Id { get; set; }
我问的原因是,当让 ReSharper 将属性转换为自动属性时,它似乎会扫描我的整个解决方案,或者至少扫描所有 aspx 文件。
从课堂外来看,我看不出两者之间有任何区别。有没有?
Is there any difference between accessing a property that has a backing field
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
versus an auto-property?
public int Id { get; set; }
The reason I'm asking is that when letting ReSharper convert a property into an auto property it seems to scan my entire solution, or at least all aspx-files.
I can't see any reason why there should be any difference between the two from outside the class. Is there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器会自动生成自动属性的支持字段,因此不应该有任何区别。
ReSharper 正在扫描所有文件,因为如果您定义了
Partial
类,则即使代码存在于物理上不同的文件中,它也可能使用支持字段而不是公共属性。例如:
ReSharper 必须扫描所有文件,因为它无法知道部分类可能在哪里定义。
The compiler generates the backing field for Auto-Properties automatically, so no, there shouldn't be any difference.
ReSharper is scanning all the files, because if you have a
Partial
class defined, it could be using the backing field instead of the public property even though the code exists in physically different files.For Example:
ReSharper must scan all files, since it has no way to know where a partial class might be defined.