I have a test application, with a class TestSeq and a method Go(), which consist of such blocks:
_writer.WriteLine("Doing foo action...");
var stopwatch = Stopwatch.StartNew();
// foo - some work here
stopwatch.Stop();
_writer.WriteDone("Results of foo action.", stopwatch.Elapsed);
In “some work” I have different calls to WCF client (CRUD actions, filters, etc.).
So, a lot of code repeating, and obviously some refactor should be done here. I think about creating a class TestAction, but I dont know what is the best way to put that “some work” part in it.
It’s seems to me that this is quite simple problem, but I just don’t know what keywords should I search for. So, I’d be glad to see answers with just a keyword (pattern name or something) or link.
I’m sure there are more, but off the top of my head, you can probably this boiler plate code in two ways.
Method 1: Use the using syntax to wrap the code of interest
Method 2: Creating a new function and passing in your block of code as a delegate