I don't quite get what it's going to let me do (or get away with :)
views:
372answers:
4
+5
A:
From Charlie Calvert's blog:
Useful Scenarios
There are three primary scenarios that will be enabled by the new support for dynamic lookup:
- Office automation and other COM Interop scenarios
- Consuming types written in dynamic languages
- Enhanced support for reflection
Read more here: http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx
CraigTP
2009-03-27 10:39:56
+5
A:
The two big areas are:
- working with COM assemblies where methods return vague types - so you can essentially use late binding
- working with DLR types
Other uses include things like:
- duck-typing where there is no interface
- Silverlight talking to the host page's DOM
- talking to an xml file.
In C# itself, this allows a few things, such as a basic approach to generic operators:
static T Add<T>(T arg1, T arg2) { // doesn't work in CTP
return ((dynamic)arg1) + ((dynamic)arg2);
}
(of course, I'd argue that this is a better (more efficient) answer to this)
Marc Gravell
2009-03-27 10:40:43
I found this a nice example in addition to your last link: http://blogs.msdn.com/lucabol/archive/2009/02/05/simulating-inumeric-with-dynamic-in-c-4-0.aspx, though I wonder what the performance impact would be.
Razzie
2009-03-27 10:48:13
@Razzie - indeed, I have a test harness ready to go as soon as the CTP includes the new bits ;-p
Marc Gravell
2009-03-27 10:59:13
A:
There are some podcasts about the feature itself and how it can be used:
- Inside C# 4.0: dynamic typing, optional parameters, covariance and contravariance
- C# 4.0 New Features - COM Interop Enhancements
- deCast - Dynamic Xml with C# 4.0 "will illustrate how you can take advantage of the dynamic functionality enabled in C# 4.0 to access Xml data in a more natural way"
f3lix
2009-03-27 11:11:56
A:
From Walter Almeida's blog: description of a scenario of usage of the dynamic keyword to enhance object orientation: Read here:
Walter Almeida
2010-06-04 07:23:30