Sample SSR Pattern Catalog Available for Download

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.
This entry was posted in dotCover Tips&Tricks, dotTrace Tips&Tricks, How-To's, ReSharper Tips&Tricks and tagged , , . Bookmark the permalink.

8 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. @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);
    }
    }

  7. Ludvig says:

    Thanks for the examples,

    I just want to add that I also seek the functionality that Robert suggested.
    That is how I wound up here.

    Question, do you have a tree to search and is that why identifiers can’t be split. Or could one be allowed to use grouping in the regexes??

    Very difficult robot-test, extremely hard, this is my 10:th time trying to read it

  8. @Ludvig
    Thanks for your input, and sorry for the overzealous captcha plug-in
    The functionality suggested by Robert is still not available at this point. I have looked into our issue tracker to see if a request is there but apparently it’s not, so I suggest that you create one.
    As to a tree, you might want to take a look at PSI browser and PSI viewer available in ReSharper Internal mode. See more about these and other internal features on Igal Tabachnik’s blog.
    As to regexps, these are not supported in SSR yet.
    Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">