markdown in WordPress – AT LAST!!!!!

Here’s some normal text interspersed with some Code, some italics and bold.

a quote

some sql

some code

and some xml too (it makes a mess of this)


Microsoft’s Task Parallel Library and the principle behind node.js

I wanted to see how Microsoft’s Task Parallel Library compared with node.js in so far as passing the next method in to the current to chain the calls indefinitely. So I created a method that iteratively adds itself to the current executing Task. The initial test was to see if the code would fail with a StackOverflowException but what I found instead was that I couldn’t get the Task to Wait unless I put the thread to sleep.

So this simple test fails, every time:

But if I swap start.Wait(); with Thread.Sleep(10); then it works fine. WFT? To cut a long story short … the ContinueWith method returns a child Task that you also need to wait for.

Obvious once you know!

So, back to the initial question – how long for a StackOverflowException? I can’t get it to fail …


Sql Server Shrink Log File

Easy with Simple Recovery




node.js calling multiple web services in parallel




Extract details from an Expression

I wanted to come up with a way of establishing the type name and property name when applying general validations within my code. So, for example for this validation:.

I have to explicitly code the exception:

What I’d like is for all this to happen when I declare the test, without double typing the type and property name.

This is still very much a work in progress but I’ve got the basics of what I’m trying to achieve by using the Expression class.

Here’s how it’s used:

And here’s the basic implementation:

This is working for these tests:


Multiple Dispatch, Double Dispatch and the Visitor Pattern

I’ve been looking into the Visitor pattern and figuring out how to make it work with overloaded methods.

Starting with the abstractions

And initial implementations

A quick test to show it’s working

All fine. So Let’s extend our Visitor with an overload of the Visit method

Sadly the test fails

But the fix is so easy with C#’s dynamic keyword

The “fix” introduces a new problem and that is if we decide to explicitly implement IVisitor the method call may not be as expected.

Extend TestVisitor1 with an explicit implementation

And we have another test that fails

The dynamic nature of the Accept method means we do not call the implementation we expected.

The fix for this it to have two versions of the Accept method


Dynamic objects part II

I decided to extend my DynamicObject class to enable me to do this:

And this:

And this (something I hope to use with Entity Framework):

The update to the code requires adding the following indexed property:

When inheriting from this class it's important to remember to store members in the underlying DynamicObject, e.g.

Here's the complete class for reference:


Dynamic Objects in a Generic World

I have a situation where I want a dynamic object that can used within generic classes and methods.

I have a generic service that accepts any instance that implements a predefined interface:

And I have a method to call the service:

Microsoft provides the ExpandoObject for use as a dynamic object but calling the service with the ExpandoObject throws an error because the ExpandoObject class does not implement the required interface IMyInterface:

So what do we do? The first thought is to inherit from ExpandoObject but that can’t be done because it is defined as sealed. There are plenty of other options to be found on the web but the first and most useful that I came across was this one: http://www.abhisheksur.com/2010/07/dynamic-behaviour-on-objects-at-runtime.html

I created my own AbstractDynamicObject:

Which I could then extend to implement the interface IMyInterface and violá everything works!


Simple Injector – How to discover the underlying Implementation Type of a decorated instance when calling GetAllInstances

I asked the question “How to discover the underlying Implementation Type of a decorated instance when calling GetAllInstances?” on stackoverflow and got a perfectly valid answer – here’s a sample implementation to prove that it would work.

Start with some test abstractions and implementations:

For this example I have defined a decorator that will disable the call to the decorated type:

And a very simple abstraction to hold the list of types to NOT be disabled:

Here’s the code to configure the container:

And finally a test to prove it works as expected:


The code above had a limitation that it would make the decision to apply the decorators only the first time the type was resolved. This was proved with a second test that failed:

I asked the question on the simpleinjector codeplex website which pointed me to an extension method that can Apply decorators at runtime

One minor change to the way the decorator is registered:

And violá – test 2 now works!