没有方法体的 Resharper Auto 属性 实现

Resharper Auto Property implement without method bodies

我使用的是最新的 ReSharper - 9。我还安装了 StyleCop。

当我实现带有属性的接口时,它会这样做:

public class MyClass : IMyClass
{
     public bool MyProperty
     {
         get
         {

         }
         set
         {

         }
     }
}

我希望它像这样实现:

public class MyClass : IMyClass
{
    public bool MyProperty { get; set; }
}

具体如何设置?

当您告诉 ReSharper 'Implement Missing Members' 时,表单中会出现一个名为 'Properties As:' 的下拉菜单。如果将其设置为自动 属性,它将以您希望的方式生成属性。您目前似乎已将其设置为 'Property with backing field'.

  1. 创建一个界面 属性
  2. 创建一个 class 来实现该接口
  3. 将光标移动到 class 声明行
  4. 按 Alt + Enter,然后选择 'Implement Missing Members'
  5. 在出现的表格中,将 'Properties As:' 设置为 'Automatic property'
  6. 按'Finish'
  7. 享受单行自动属性。

你应该在屏幕截图中标记设置

我在 Resharper 9 上发生了类似的事情,我在 Resharper 问题跟踪器中发现了 this 相关的错误。安装更新为我修复了它。您也可以尝试该错误中提到的 Alt + Insert 解决方法。