In ReSharper 9, how to generate autoproperties from missing members?
Asked Answered
B

1

6

In ReSharper 8, when a class was missing interface members (properties), I would Alt+Enter and select "Implement Missing Members", which would generate autoproperties like this:

public class MyClass : IHasId {
    public int Id { get; set; }
}

However, in ReSharper 9, the following is generated:

public class MyClass : IHasId {
    public int Id {
        get { throw new System.NotImplementedException(); }
        set { throw new System.NotImplementedException(); }
    }
}

I have set R# to create automatic properties under "Member Generation", still no effect.

Is this a bug, or am I missing something?

Borisborja answered 8/1, 2015 at 10:22 Comment(2)
It seems ReSharper can "fix" this property afterwards with Alt+Enter to convert it to an autoprop or to one with backing fields. Not sure R#8 could do that. But yes, odd that it cannot just create autoprops to begin with.Shovelnose
I have created a bug report: youtrack.jetbrains.com/issue/RSRP-430040Borisborja
S
7

It seems there's some odd options at work here that impact each other.

Do this:

Navigate inside the class (ie. not on the squigglies on the class or interface), and hit Alt+Insert, for generate code, then select "Missing Members".

In the dialog that pops up, only change an option at the bottom, to generate automatic properties:

ReSharper 9: Implement missing members

Then OK out that dialog, note that I didn't pick any items to actually implement. Then try Alt+Enter on the class/interface again.

This seems odd to say the least, but now at least you can "fix" it.

Shovelnose answered 8/1, 2015 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.