Mike Nichols - Son of Nun Technology

Replace Code in Visual Studio

I learned a little trick I reckon everyone else knows about. I am trying to grow my chops on Visual Studio and have been encouraged recently by some posts by JP Boodhoo and Kevin Atwood on things to increase productivity (speed, acccuracy, etc). One thing that has alluded me in the past was when I wanted to replace chunks of code that, having a pattern that I know I could write a Regular Expression for, would accept that regular expression and then turn around and ONLY replace the bits in the Reg Ex. Ok, that sentence sucked so here's an example.

In my Presenters I wanted to replace the code that had this:

        public new ISomeView View

        {

            get { return ((ISomeView)base.View); }

        }

I simply wanted to get rid of the 'new' declaration in there and return a class field instead. I knew I could apply reg ex's to Find stuff in my codebase, but I wasn't sure how to trap variables during a reg ex to preserve them during the replace...In other words, I'd want to keep the 'ISomeView' text above. So, I opened up the Replace In Files from the Edit menu and made my dialog box like this:

The curly brackets in the 'Find' are a Tag that gets captured and then preserved in the '\1' part of the Replace field. There is probably a better way to do this, but I at least learned a little trick. I wonder if ReSharper has some similar and more advanced methods for this kind of thing?
Hope this helps some one.