Recently, I started playing around with C# dynamic, and blogged how it could be used to call static class members late bound . Today, I was talking to Phil Haack , who I think had talked to ScottGu , and he mentioned that it would be cool to use dynamic to simplify data access when you work directly with SQL query. So I thought I’d play around with that, and it didn’t take much code to make it work nicely. So the scenario is that you’re not using any fancy O/R mapper like LINQ to SQL or Entity Framework, but you’re directly using ADO.NET to execute raw SQL commands. It’s not something that I would personally do, but there are a lot of folks who prefer this over the higher level data access layers. So let’s look at an example...
By now, you’ve probably heard that C# 4.0 is adding support for the dynamic keyword, which introduces some aspects of dynamic languages to C#. I had not had a chance to really try it, but recently I was reading Bertrand Le Roy’s post on the topic, and was sort of looking for a good opportunity to use it. Today, I found a scenario which I thought it would work great for, but it turned out not to be supported out of the box! The scenario is to call static class members using dynamic. That probably sounds crazy, so let’s look at an example. Say you have these two classes: public class Foo1 { public static string TransformString(string s) { return s.ToLower(); } public static string MyConstant { get { return "Constant from...