Implementing an autoproperty on derived classes from the base class?
-
13-01-2021 - |
Domanda
I have and interface that I have made updates to. I would like to implement all my changes in my derived classes as auto properties, but they get implemented with the NotImplemented exception. Is there a way to set properties created by ReSharper 6 as autoproeprty?
Soluzione
Currently there are two different ways to implement missing interface members.
The first is invoked by pressing Alt+Ins while in the body of the implementing class, and choosing Implement missing members
. In the resulting dialog, you can choose that properties are implemented as autoproperties.
The second is invoked by pressing Alt+Enter while on the red squiggly of the definition statment of the implementing class, and choosing Implement members
. The bodies of the generated members in this case are controlled by the setting in ReSharper | Options... | Languages | Common | Members Generation
- where 'autoproperty' is not an option.
There is an open YouTrack issue to improve the UI in the second case to provide an autoproperty option - JetBrains have marked it as Critical, so it might make it into 6.1, else we'll have to wait for 7.
Altri suggerimenti
Here is a hacky workaround:
- Temporarily change the interface into a class.
- Make the desired property
public
and copy its definition to the clipboard - Perform the Push Members Down refactoring which will copy the member into implementors.
- Revert the class back to being an interface and re-add (using paste) the property to the interface.
Having to do this sucks, but it works.