littlecharva
littlecharva

Reputation: 4244

Advanced Templates/Snippets for Visual Studio

I'm using Visual Studio 2013 with Resharper 8.1 installed and I'm all about finding shortcuts for regular tasks. One such task that I do regularly is add new constructor dependencies to MVC Controllers. So for example, I might have the following:

public class MyController : Controller {
    private readonly ICustomerManager _customerManager;

    public MyController(ICustomerManager customerManager) {
        _customerManager = customerManager;
    }

Now I want to add in an IOrderManager, so I have 3 different lines to adapt: I have to add a private variable to store it, add a parameter to the constructor, and add a line inside the constructor to set the private variable.

I'd love to be able to write a macro/template/snippet that would allow me to enter "IOrderManager" and have it add all the code for me. Is there any way I can do this in VS2013 or Resharper?

Upvotes: 0

Views: 46

Answers (1)

citizenmatt
citizenmatt

Reputation: 18573

The easiest thing is to add the field manually, then Alt+Enter and let ReSharper initialise the field from the constructor. It will add the parameter, and initialise the field with it.

Upvotes: 1

Related Questions