.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.

download

Right-click -> Save Link As...

installation

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

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

File templates:

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

Have a template that I'm missing here? !