Expression Trees

GetValueOrDefault() For An Expression of Arbitrary Length Using Expression Trees

In my most recent project we had to support classes with fairly deep object graphs where any of the nodes could validly be null. We didn't want to have lots of 'if not null' checks everywhere, so I wrote an extension method which takes an expression of any length and returns the expression value or a default value if any of the nodes are null. Here's the extension method code, along with an overview of how it works.

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.

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

I recently wrote a Type.GetInstance() extension method, and used the opportunity to play around with Expression Trees, which I'd recently read up on. Here's the set of extension methods I came up with, which allow you to quickly create an instance of a Type from the Type itself.