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<Type>() 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.

Related Articles:

    Post Footer automatically generated by Add Post Footer Plugin for wordpress.

    This entry was posted in resharper. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
    • http://blog.donnfelker.com Donn

      Cool stuff, but if you use var for everything then it kind of falls down. :( But cool stuff though !