How to add a property to an existing constructor?

In Visual Studio, if I add a new property to a class which has an existing constructor, I can highlight the property, press Ctrl + . , and select the option "Add property to constructor", which will add a new parameter to the constructor and set the value of the property to the parameter.

How do I do the same in Rider? The only thing I can see that is similar is "Generate constructor", but this only seems to generate entirely new constructors, not add parameters to existing ones.

Many thanks

0
9 comments

     Good day.
     Thanks for your request.

     To add a new property or field to the constructor, you can place the caret on the name, then use “Alt + Enter” hotkey,  select “Initialize field/property from constructor” value from the drop-down list.

     Also, I attached the video of how it works.
     https://recordit.co/y5DE636Kd3

     Kind regards,
     Maxim Isaev.

0
Avatar
Permanently deleted user

Thanks, but I think you've replied to the wrong thread

0

 Sorry for the mix up, you should see the correct reply now.

0
Avatar
Permanently deleted user

Thank you, this is clear now

0

Rider 2023.1 - I can't figure out what the reason is, but I don't see this option.

 

0

Hi Leni8ec

It seems like you don't have analyses enabled in this file. Could you please check if there is an OFF sign on the top right of the Editor tab? Also, could you please clarify where is the caret placed? 

Thanks! 

0

Hello, 
I did not disable the analysis - it works fine.

Now I noticed that if you create a private autoproperty, it works. 
But for some reason it doesn't work on private variable.

At the same time, if you change the variable's visibility to public or protected, everything is fine.

Even if I create a new private variable with a different name - still, there is no option to add this variable to the constructor.

 

0

One more thing - a private variable is not highlighted as unused, although it is (this may be the intention, but I did not pay attention to it before)

0

Hi Leni8ec

Sorry for the delay. 

It seems like you've met one of the known issues. The first is fixed in the Rider 2023.1.1 bugfix, and the second  in the newest Rider EAP.

Please install one of these builds and check if it helps. If the issue still persists in EAP, please upload a repro solution to our server and share the ID. 

Thank you in advance! 

 

 

0

Please sign in to leave a comment.