Click here to Skip to main content
15,881,173 members
Articles / API

Expression API Cookbook

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Mar 2014CPOL2 min read 12.6K   1  
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)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions

 
-- There are no messages in this forum --