ReSharper 5 – Structural Search and Replace
I found a use today for a new feature that will be in ReSharper 5.0 - “Structural Search and Replace”. Essentially it’s a way to add code matching templates into R# to add new refactoring patterns in addition to those that come in the box.
For example, Microsoft recommends (and Code Analysis/FxCop generates appropriate warnings) if you are doing a comparison between a string value and an empty string, to use the String.IsNullOrEmpty() method.
I always wanted R# to make this change for me, and now I can:
Go to Resharper Tools Patterns Catalog
- Click on ‘Add Pattern’
- Enter “
$value$ == ""“ in the Search Pattern textbox.
- Click on ‘Add Placeholder’ and add an ‘Expression’ placeholder named ‘value’ of type System.String
- Enter “
string.IsNullOrEmpty($value$)” in the Replace Pattern textbox
- Ensure Pattern Severity is set to at least ‘Show as suggestion’
- Click on ‘Add’
R# will now use this pattern and highlight code that matches. You can then hit the QuickFix shortcut (Alt-Enter by default) and get a smart tag offering to refactor/replace your code.
If you can’t wait for the final release of ReSharper 5 (due in the next few months) then install beta 2 or one of the recent nightly builds.
If one wasn’t enough this week, today I passed another exam – 70-451 PRO: Designing Database Solutions and Data Access Using Microsoft SQL Server 2008.
Combining that with [yesterday’s success]/2010/02/passed-70-433.html) means I am now a Microsoft Certified IT Professional (MCITP): Database Developer 2008.
Doing the exams are an interesting (and educational) process but they have other advantages too – they’ll be useful to my employer (LobsterPot Solutions) and might benefit efforts for me to become a Microsoft Certified Trainer.
This morning I took the Microsoft exam “TS: Microsoft SQL Server 2008, Database Development 70-433”. I was quite chuffed after I hit the ‘Finish’ button and it said I’d passed!
One thing different about today’s exam was that I chose to do it at Rockfort International Pty Ltd. An impressive name, but it turns out they appear to be a 2-man outfit in a quite tiny office. I wasn’t even sure I was in the right place until the guy turned up and confirmed that yes they did do exams! Having said all that, once I sat down at the exam PC it was pretty good – quiet, comfortable and the PC had a reasonable screen. I’ve done most of my other exams at Excom, and last time I was there they still had a crumby old CRT monitor (running at a really low refresh rate) and that room had pretty noisy air conditioning. So even though the office may not be quite as swish, I’d rate the actual examination environment higher.
Over the weekend I was doing some study toward the exam and came across the following things that were new to me. Some of them may be obvious to others, but they’re not things I’ve used before or been aware of.
- You can create filtered indexes (an index that has a WHERE clause)
- An indexed view needs to use WITH SCHEMABINDING, and as a consequence the index must be UNIQUE CLUSTERED.
- Run a table-valued function against all the rows of a query using APPLY.
Note – these were things I came across BEFORE I did the exam. I am definitely not indicating these topics were either in or out of the exam (and no, there’s no hidden meaning here, I really mean that). All I am saying is that by reviewing the curriculum I happened to learn some new things.
Finally, let me pre-empt the inevitable lazy sod who emails me and asks for some hints or answers to this exam (apart from the fact that by taking the exam, I’ve agreed to Microsoft’s Non-Disclosure Agreement which includes not “Disseminating actual Exam content” ) ..
Do what I did – use the product, and know all (or enough of) the stuff it says you need to know and you should pass!