Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / API

Expression API Cookbook

0.00/5 (No votes)
4 Mar 2014CPOL2 min read 12.8K  
Expression API Cookbook

This blog post is a strange one in a lot of ways, it is more of me pointing out a set of recipes and linking through to a related article. So what are the recipes, and what will it show you, the reader how to do?

Well I am going to start with a wee story first (don’t worry, the point is on its way). A while back, I got this email out of the blue from this guy in the states who was creating a MVVM framework for Windows 8, and I have kept in contact with this dude (and he really is a dude, if I can convince him to upload an image, you will see what I mean) and we got talking about his IOC container within his MVVM framework, which is like MEF for Windows 8.

Looking through Ian’s code, it was immediately obvious to me, than Ian really (and I do mean really) knew how to use the Expression API within .NET. This namespace has always intrigued me, so I talked to Ian about the merits of writing a joint kind of article, where we would effectively come up with some scenarios to solve using the Expression API.

Ian said he would be more than happy to write the code to any scenarios I could come up with, if I was happy to do the article writing side of things. This seemed a very fair way to do it, so we have done just that.

Now you may be asking what is so cool about the Expression API, well one thing I quite like is that you can literally write entire programs in it, and another thing that you see time and time again, is creating compiled lambda expressions that have been built up on the fly, which compile down to a delegate, so provide uber fast performance when compared to reflection. That is why the Expression API can be useful (at least we feel that way).

That is essentially what the associated article is all about, we have a bunch of scenarios that I came up with (which I hope are good ones) which Ian has coded up. The examples range from simple property get/set through to some rather complex examples where we show you how to do things like how to create If-Then-Else Expressions and compute a HashCode for an object based on its property values.

Here is a list of the scenarios we will be covering:

  • Change tracker
  • Convert
  • Generic object HashCode computation
  • If-Then-Else
  • Property get/set
  • Dynamic where

Want to know more, please read the full article over here:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)