Generate Constructor below properties

Viewed 243

When I choose the Quick Action Generate Constructor... it defaults to putting the constructor above the properties/fields

enter image description here

But I want it to be below

enter image description here

I see the ctor snippet located here but it's not clear to me how to edit it (or if it even is the right file for this) to do what I want

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC#\Snippets\1033\Visual C#\ctor.snippet
2 Answers

When I choose the Quick Action Generate Constructor... it defaults to putting the constructor above the properties/fields

As other's have mentioned, this is either a "code fix" and or "reformatting". You've already witnessed the default of this quick action as it inserts above your properties, this is because of where you're doing it from; it will insert it based on the current line/cursor location.

To do what you want:

  1. Create a new line below your properties
  2. Click the Quick Actions and then Generate constructor...

Here's a quick gif of it working on my end...

enter image description here

What you're doing there isn't a snippet, to access that type ctor in the code window followed by two TAB characters.

What you're doing there is a "code fix" built into the compiler itself, Roslyn. The code fix decides where it places the code (and unfortunately they decided to go with individual assignments instead of a single expression body tuple assignment). You have no chance of changing it yourself without building a custom compiler (which is not terribly difficult), but you can just make your own code fix for this if you want.

Related