Weekly Keyboard Shortcut #5: ReSharper's Generate Type Constructor

Welcome back to Weekly Keyboard Shortcuts with your host, Slowness McMousington.

Ever feel like there’s a productivity boost right at your fingertips and you’re not using it? Ever watch someone puke code onto the page like some kind of Hollywood-hacker? If you’re slow and jealous like me, you want to start building your repertoire of Visual Studio/ReSharper keyboard shortcuts now.

I believe that we can achieve keyboard shortcut Zen if we just learn the ones that make our lives easier. We don’t have to digest the canonical Visual Studio Shortcuts or the ReSharper Docs. We just need to grab one or two and really focus on instilling them into muscle memory.

Last week, we looked at ReSharper’s Go to File Member. This week, I’ll give you the Faster and Fastest version of a very fine keyboard shortcut.

Generating Type Constructors

The Slow Version

Say you have a class that has a bunch of auto-implemented properties that you intend for the constructor to initialize. Using the propg Visual Studio snippet, you quickly enter all seven auto-properties.

You know the ctor snippet, which is also built into Visual Studio, so you use that to make your empty constructor - then proceed to type out each constructor parameter. This is slow, and error prone… what if you forget a parameter?

Here it is in (slow) action:

Faster: Alt + Insert

ReSharper offers one nice solution called Generate Type Members, called by pressing Alt + Insert. This brings up a menu for generating several type members, including a Constructor. Choose the properties you want to initialize and you’re done:

Fastest: The ctorp Snippet

I actually stumbled on this snippet after building several classes like this example… yes after. But now, I use it exclusively. As for documentation, I found it mentioned here.

If you’re familiar with the ctor snippet that’s already provided to you by Visual Studio, it works the same way, except it includes all of your properties:


Hope you get a chance to try this shortcut!

If you haven’t already, make sure you sign up for my newsletter so you can get these sent right to your inbox! Also, feel free to send me your favorites - I’d love to hear!

Related posts:

comments powered by Disqus