Resharper templates: Don’t forget the Macros


I use Resharper templates (among other features) on a daily basis.  Most of them create very small pieces of code that I use VERY frequently.  For instance, I have a set of templates that help me build out my test classes and cases very quickly.  One of the very cool features you can add to your templates is to use Macros that let’s R# do more work for you.

The lates template I created was to create the MockRepository.GenerateStub() line for me.  It’s a simple one liner, with one variable $INTERFACE$

image

I then added a Macro to the template to guess the type the variable should be.

image

Now I can use this macro ( it’s named gs) on this line.

image

And it fills out the generic type of the GenerateStub method for me.

image

As you can see, this is really a big time saver, especially for the really tedious generic types.  Small time optimizations like these add up over a few hundred tests.

Cooking With Pablo: Chicken Cacciatore