.NET 4.0: What is the true purpose of dynamics?
I haven't used 4.0 in depth, but have played with dynamics in a sample app to see them in action. At first, it would appear that dynamics are a sort of way for developers to "hack" code so that they can implement the architecture of generics and/or inheritance in a开发者_Go百科n application that wasn't written with such architecture in mind.
Other than bringing back the old VB6-style object, what advantages are gained by introducing dynamic types into your app? In other words, how can dynamics be used "wisely"?
The best use of dynamic
in .NET is when interacting with APIs from dynamic typing languages such as JavaScript and Python. You need the dynamic keyword to more easily interact in such architectures and I would suspect that any other use of dynamic is not wise, i.e. a code smell.
From the dynamic reference:
The dynamic type simplifies access to COM APIs such as the Office Automation APIs, and also to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM).
精彩评论