Callum Linington
Callum Linington

Reputation: 14417

Resharper Auto Property implement without method bodies

I'm using the latest ReSharper - 9. I also have StyleCop installed as well.

When I implement an interface with properties it does this:

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

         }
         set
         {

         }
     }
}

I want it to implement like this:

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

Exactly how do I set this up?

Upvotes: 1

Views: 179

Answers (3)

jsw
jsw

Reputation: 175

I had a similar thing happen on Resharper 9, and I found this related bug in the Resharper issue tracker. Installing the update fixed it for me. Also you could try the Alt + Insert workaround as mentioned on that bug.

Upvotes: 2

Callum Bradbury
Callum Bradbury

Reputation: 956

When you tell ReSharper to 'Implement Missing Members', there's a dropdown in the form that appears called 'Properties As:'. If you set this to Automatic property, it will generate properties in the manner you want them to. It looks like you currently have it set to 'Property with backing field'.

  1. Create an interface with a property
  2. Create a class to implement that interface
  3. Move your cursor onto the class declaration line
  4. Press Alt + Enter, and choose 'Implement Missing Members'
  5. On the form that appears, set 'Properties As:' to 'Automatic property'
  6. Press 'Finish'
  7. Bask in your single line Auto Properties.

Upvotes: 0

Andrzej Gis
Andrzej Gis

Reputation: 14316

You should mark the setting from the screenshot

enter image description here

Upvotes: 0

Related Questions