.NET logo

resharper live templates & file templates

home | software | resharper templates

Any C# developer who fears RSI (repetitive strain injury) or RBI (repetitive boredom injury) should at least try the ReSharper add-in for Visual Studio .NET. Among its many features is the ability to generate frequently used code blocks from shortcuts (live templates) -- a feature that VS2005 does, but not as well. You can also create new files from templates (er, file templates).

Best of all, you can define your own templates. I'd like to share my favourites with you here.


Right-click -> Save Link As...


Import these templates via the ReSharper options form. Here's a screenshot from ReSharper 2.5 showing live templates options. The import button is indicated by a red circle:

ReSharper options form showing live templates

Similarly, here are my file templates:

ReSharper file templates

Be sure to import the live templates and the file templates to the correct areas. You can set them per user, per solution, or per user/solution.

what's included

Live templates

If a parameter of type IList has zero items, throw an exception.
If a parameter is null, throw an ArgumentNullException.
Creates an empty NUnit test case.
Create an empty try/catch block (complements the surround-with operation).
Checks if Control.InvokeRequired, and if so, calls Invoke with a delegate for the current method.
NMock expectation -- Expect Once On
Create an NUnit setup method.
Create an NUnit teardown method.

File templates:

NUnit Test Fixture
A new and empty test fixture with correct using statements and default header.
A custom subclass of System.Attribute. Sealed in accordance with the FxCop recommendation.
A new derivation of System.Exception with all default constructors, including that requried for serialisation.

Have a template that I'm missing here? !