I just read a chapter in a programming book about Dynamic types. Although they are quite neat I cant think of a single real world example where I would use them. Does anyone here actually use them and for what?
C# Dynamic types
c#;dynamic typing
I've used dynamic to evaluate logical expressions represented in an object graph, where using the dynamic keyword allowed me to largely ignore the types of the operands.For example, if my expression graph was an arithmetic expression with a multiplication operator (e.g. 12 * 1.3), I would use dynamic to store the operands 12 and 1.3, and dynamic again to catch the result from the multiplication.Without dynamic I would be forced to deal with concrete numeric types (int/long/decimal/float, etc...) and the resulting code bloat. My dynamic solution requires very little code and is much easier to grasp and maintain.My initial idea was to turn my logical expressions into snippets of Python or Ruby, then run these snippets through IronPython or IronRuby to evaluate the result. It struck me all I required from Python or Ruby was their dynamic typing, so I was very happy to see that dynamic affords Python-like typing for C#. 