Most common C # 4.0 dynamic type applications

Now that people have been using C # 4.0 for a while, I thought that I would see how people most often use the “dynamic” type, and why did it help them solve the problem better than they did before?

+5
source share
2 answers

For example, when using reflection.

Example: Example:

object calc = GetCalculator();
Type calcType = calc.GetType();
object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 });
int sum = Convert.ToInt32(res);

what will be:

dynamic calc = GetCalculator();
int sum = calc.Add(10, 20);

This is a big improvement, I think.

But there are more items where this can come in handy. For example, when working with objects of COM interoperability this may come in handy, see: http://www.devx.com/dotnet/Article/42590

+3
source

, IronPython/IronRuby, , , #

+2

All Articles