Visual Studio 2012 Find/Replace With Tagged Expressions

If you ever wanted to do some heavy duty find/replace options in VS 2012, you’ll find yourself needing to use the Regular Expressions option.

One of the most useful things you can do with it is called Tagged Expressions, or backreferences.

Unfortunately, nearly all the online documentation on this is completely wrong.

So I’ll just give a little example.  I’m doing some refactoring, and I have lots of blocks of code that look like this:

Using com As New SqlCommand("SomeCommandNameHere", conn)

and of course each line like this has a different command name.  I want to change the code above to look like this:

Using com As System.Data.IDbCommand = dbProvider.CreateDataCommand()
com.CommandText = "SomeCommandNameHere"

So to achieve this, I use the find/replace below.  You can see that I have to escape a number of characters in the FIND and I’m matching the command name with (.*).  The  () wrap each tagged expression, not { } like all the documentation says.  In the bottom, I just reference the result by saying $1 for the first tagged expression (not \1 like msdn says).



Looking for fraud on your credit cards

This is interesting:

They will scan your credit card transactions looking for possible fraudulent activity and alert you to it.

BillGuard is a personal finance security service that analyzes millions of consumer billing complaints to find deceptive, erroneous and fraudulent charges on your credit card and debit card bills.

I might give it a try.


The StackExchange Mini Profiler is a nice tool to help you see where your pages and queries are spending most of their time. 

It gives you a little jewel in your page that you can click on to see info like:



While setup is easy, I was going to build a way for it to be enabled/disabled on a per-session basis so that developers could tur n it off and on as needed.  So I decided to make it into a nuget package.

The nuget package is here:

and the source is hosted here:

Adding a reference to this from your web project will cause the StackExchange MiniProfiler to profile for all requests (by default), but only show them to you if you choose to enable it for your session.  To enable display of the values, you simply browse to ~/MiniProfiler/true (or false to turn it back off).

Because the MiniProfiler will cache up to 15 request profiling sessions, this means a developer can notice a page took a long time to load, and after it completes, browse to ~/MiniProfiler/true to see the profile session that contains the info for what caused the slow page processing on the earlier request.

If you don’t want the profiler to always be monitoring, you can disable it with

MiniProfilerHttpModule.AlwaysProfile = false;

in your application startup code.

By default, the application will also always profile local requests.  This can be disabled with:

MiniProfilerHttpModule.AlwaysProfileLocalRequests= false;

Fluent .Net State Machine

I was listening to an episode of DNR featuring Chris Patterson who is behind MassTransit, an open source .net service bus.  I’d recently been working a little with NServiceBus so I was interested to hear his take on the subject.  One of the interesting things to come out of the interview was a quick mention of another of his projects, Automatonymous, which is a .net state machine that operates in a fluent interface.

So for example:

public class BigComplexStateMachine :
//declare states
public State InProcess { get; set; }
public State Delayed { get; set; }
public State OnHold { get; set; }
public State Delivered { get; set; }
//you get 'complete' and 'initial' for free

//declare events
public Event Ordered { get; set; }
public Event Delay { get; set; }
public Event Hold { get; set; }
public Event<CustomEventData> Deliver { get; set; }

//must NOT have arguments
public BigComplexStateMachine()
//inform the statemachine of your states
State(() => InProcess);
State(() => Delayed);
State(() => OnHold);
State(() => Delivered);

//inform the statemachine of your events
Event(() => Ordered);
Event(() => Delay);
Event(() => Hold);
Event(() => Deliver);

//define transitions
.Then(state=> { /*do cool stuff */ })

When(Deliver) //notice the new param available
.Then((state, @event) => { /* do cool stuff */ })

//so on and so forth
* During(state, When(event).[StuffIWantToDo].TransitionTo(state));
Anytime(When(Hold) //also support an anytime concept
.Then(state=> { /*cool stuff*/ })
.Complete() //convenience method


Some more info here as well.

Telerik acquires Fiddler

Interesting move here by Telerik to acquire Fiddler.

I’m guessing they will integrate Fiddler into some type of testing framework.  I’ve used Fiddler a lot over the years.  It’s great for looking at the details of network traffic and diagnosing issues to do with HTTP of out of band requests.