What ReSharper 4+ live templates for C# do you use?

11,983

Solution 1

Simple Lambda

So simple, so useful - a little lambda:

Shortcut: x

Available: C# where expression is allowed.

x => x.$END$

Macros: none.

Solution 2

Implement 'Dispose(bool)' Method

Implement Joe Duffy's Dispose Pattern

Shortcut: dispose

Available in: C# 2.0+ files where type member declaration is allowed

public void Dispose()
{
    Dispose(true);
    System.GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
    if (!disposed)
    {
        if (disposing)
        {
            if ($MEMBER$ != null)
            {
                $MEMBER$.Dispose();
                $MEMBER$ = null;
            }
        }

        disposed = true;
    }
}

~$CLASS$()
{
    Dispose(false);
}

private bool disposed;

Macros properties:

  • MEMBER - Suggest variable of System.IDisposable - Editable Occurence #1
  • CLASS - Containing type name

Solution 3

Create new unit test fixture for some type

Shortcut: ntf
Available in: C# 2.0+ files where type member declaration or namespace declaration is allowed

[NUnit.Framework.TestFixtureAttribute]
public sealed class $TypeToTest$Tests
{
    [NUnit.Framework.TestAttribute]
    public void $Test$()
    {
        var t = new $TypeToTest$()
        $END$
    }
}

Macros:

  • TypeToTest - none - #2
  • Test - none - V

Solution 4

Check if a string is null or empty.

If you're using .Net 4 you may prefer to use string.IsNullOrWhiteSpace().

Shortcut: sne

Available in: C# 2.0+ where expression is allowed.

string.IsNullOrEmpty($VAR$)

Macro properties:

  • VAR - suggest a variable of type string. Editible = true.

Solution 5

Create new stand-alone unit test case

Shortcut: ntc
Available in: C# 2.0+ files where type member declaration is allowed

[NUnit.Framework.TestAttribute]
public void $Test$()
{
    $END$
}

Macros:

  • Test - none - V
Share:
11,983
Rinat Abdullin
Author by

Rinat Abdullin

Rinat Abdullin is an international software engineer and consultant for the distributed applications and cloud architectures. About Me | Blog on CQRS, Clouds and .NET development

Updated on June 26, 2022

Comments

  • Rinat Abdullin
    Rinat Abdullin almost 2 years

    What ReSharper 4.0 templates for C# do you use?

    Let's share these in the following format:


    [Title]

    Optional description

    Shortcut: shortcut
    Available in: [AvailabilitySetting]

    // Resharper template code snippet
    // comes here
    

    Macros properties (if present):

    • Macro1 - Value - EditableOccurence
    • Macro2 - Value - EditableOccurence