Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic internals. Introductions  Alexandru Ghiondea  C# Compiler QA  

Similar presentations


Presentation on theme: "Dynamic internals. Introductions  Alexandru Ghiondea  C# Compiler QA  "— Presentation transcript:

1 Dynamic internals

2 Introductions  Alexandru Ghiondea  C# Compiler QA  ghiondea.alexandru@microsoft.com ghiondea.alexandru@microsoft.com  http://blogs.msdn.com/alexghi http://blogs.msdn.com/alexghi  What is your programming language of choice?  Do your apps interop with COM? Do you use dynamic languages?  Have you seen C# 4.0 before?

3 C# 4.0 language features  Named and Optional parameters  Omit “ref” for COM calls  noPIA  Co&Contra Variance  Dynamic

4 Why dynamic?  There is a lot of interest in accessing the highly dynamic object model of HTML DOM  COM is heavily used and the interop code could be easier to read and write  Dynamic languages are becoming increasingly popular  We need a unified way to work with all of the above

5 Architecture Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPythonIronRubyC#VB.NETOthers…

6 How dynamic works  We have a new type called dynamic  Calls on variables of type dynamic are treated differently by the compiler  We package extra information about the call  Calls can be: Method calls, property access, indexer call, operator call  There is a C# runtime binder to interpret the information (at runtime)  It uses the runtime type for all dynamic arguments  It uses the compile time type for all other arguments

7 CLR How dynamic works (2) Exe CompileRun Bind call Expression Tree Dynamic Call Delegate DLR Cache COM Binder IronPython Binder C# Runtime Binder …

8 IronPython, PowerPoint and C#

9 Under the cover  What is the Dynamic type?  There is no dynamic type. There is only object!  What operations are supported?  A variable of type dynamic is assumed to support any kind of operation (method call, property access, operator call and indexer call)  How is the information about the call stored?  Using CallSites objects the compiler packages data about the call

10 What does a CallSite contain?  Information about the call being made  What type of call (method call, property, operator, etc)  The name of the member  The context of the call  The type arguments for the call  Information about the parameters and return types  Is it a constant, is it passed by-ref, etc

11 Dynamic and CallSites

12 Dynamic FAQ  When do you go dynamic?  When the target of the call or any of it’s parameters are dynamic  What is the return type of a dynamic call?  It is dynamic in most cases*  *What about conversions and constructors?  They are dispatched at runtime, but their return type is known at compile time

13 Dynamic FAQ (2)  What about private methods?  Information about the context of call is embedded in the CallSite allowing the Binder to “do the right thing”  Calling a method off a non-dynamic target with dynamic arguments. (c.M(d));  It works as expected!  Can dynamic “cross” assembly boundaries?  Yes, we decorate any dynamic parameter or return type with a DynamicAttribute  It works for generic types constructed with dynamic as well

14 Dynamic FAQ (3)  Can I use Named and Optional with dynamic?  Yes!  And also Co & Contra variance  Where can’t I use dynamic?  Lambda expressions  LINQ  Can’t use dynamic and method groups  throw or catch statements

15 Return type, private methods and generics

16 Build you own dynamic object  It’s simple!  Implement IDynamicObject  Derive from DynamicObject  Implements IDynamicObject

17 I want to be dynamic!!!

18  C# 4.0 Samples and Whitepaper  http://code.msdn.microsoft.com/csharpfuture  Visual C# Developer Center  http://csharp.net http://csharp.net  C# team member’s blogs on dynamic  http://blogs.msdn.com/cburrows/ http://blogs.msdn.com/cburrows/  http://blogs.msdn.com/samng/ http://blogs.msdn.com/samng/  http://blogs.msdn.com/sreekarc/ http://blogs.msdn.com/sreekarc/  http://blogs.msdn.com/alexghi/ http://blogs.msdn.com/alexghi/ Additional Resources


Download ppt "Dynamic internals. Introductions  Alexandru Ghiondea  C# Compiler QA  "

Similar presentations


Ads by Google