February 2012 Entries

A Super-Fast C# Extension Method using Expression Trees to Create an instance from a Type

Having written an extension method to create an instance from a Type and been a bit underwhelmed by its performance, I looked into exactly what was happening and have now got it working much, much faster. Here's how.

Clean Code: Writing Readable Unit Tests with Domain Specific Languages

I'm currently reading Clean Code: A Handbook of Agile Software Craftsmanship by 'Uncle Bob' Martin, which includes a section on writing readable unit tests. I've had an article about using Domain Specific Languages (DSLs) to write readable unit tests in the works for a while now, and was inspired to finish it off using a 'clean' unit test from the book.

C# Performance: new vs Func vs Activator.CreateInstance()

I recently wrote an extension method which uses an Expression Tree to create a Func which creates an instance of an object from its Type. With that done I thought I'd check the performance difference between my method and Activator.CreateInstance(), which it was intended to replace. Here's what I found.