Sample SSR Pattern Catalog Available for Download

June 2nd, 2010 by Jura Gorohovsky

A while ago we introduced Structural Search and Replace, a new powerful feature in ReSharper 5 that lets you search for custom code patterns and replace them with other patterns, facilitating batch removal (or improvement) of stinky code.

We were hoping to include a set of ready-to-use search and replace patterns into ReSharper 5.0 release but it just didn’t happen. Instead, we’re publishing a sample Pattern Catalog on the web site for you to download.

The sample Pattern Catalog currently contains 17 patterns to search for and replace unreachable code, redundant compound assignments, clumsy method chains, and other pieces of code that you’d better get rid of.

As soon as you’ve downloaded and unzipped the Pattern Catalog, do the following to import it:

  1. In Visual Studio, choose ReSharper | Tools | Pattern Catalog.
  2. Click Import and select the XML file that contains the sample Pattern Catalog.

Tags: , ,

6 Responses to “Sample SSR Pattern Catalog Available for Download”

  1. Omer Mor Says:

    Thanks for the samples.
    I found a small bug in one of them:
    x.GetType() == typeof(Y)
    does not equal to
    x is Y

    i.e
    (”string” is object) == true
    but
    (”string”.GetType() == typeof(object)) == false

  2. Joe White Says:

    Yeah, I spotted the same bug.

  3. orangy Says:

    The pattern says about Value Type, guys. And matches only inheritors of ValueType :)

  4. robert Says:

    I am probably just missing something, but I want to find a pattern:

    public MyTypeName[] VarName {get; set; } // an array of MyTypeNames

    and turn it into:

    private readonly Collection varName = new Collection();
    public Collection VarName {get{ return varName;}}

    I am having trouble turning the Pascal Cased VarName to the Camel Cased varName. Any suggestions?
    (real code is probably a little different as I just typed this in.)

  5. Jura Gorohovsky Says:

    @robert,

    There’s currently no way to get a search placeholder and divide it into two placeholders in the replace pattern. We’re working on making scenarios like yours possible but no schedules yet :(

  6. Richard Says:

    Strange - “x.GetType() == typeof(Y)” is almost exactly the code you get when you use the “Generate Equality Members” tool:

    struct Test
    {
    public int Value;
    }

    becomes:

    struct Test : IEquatable
    {
    public int Value;

    public bool Equals(Test other)
    {
    return other.Value == this.Value;
    }

    public override bool Equals(object obj)
    {
    if (ReferenceEquals(null, obj))
    {
    return false;
    }
    if (obj.GetType() != typeof(Test))
    {
    return false;
    }
    return Equals((Test)obj);
    }

    public override int GetHashCode()
    {
    return this.Value;
    }

    public static bool operator ==(TestMe left, TestMe right)
    {
    return left.Equals(right);
    }

    public static bool operator !=(TestMe left, TestMe right)
    {
    return !left.Equals(right);
    }
    }

Leave a Reply