1
Managed Languages in VS2010
Mike TaultyDeveloper & Platform GroupMicrosoft [email protected] http://www.mtaulty.com (/DevWeek.zip)
Format of the session
11
22
33
Before we get started...
What’s been going on with Visual Basic and C# since 2002?
Future commitment (from PDC 2008)“Co-Evolution” of these 2 languagesMajor features to surface in both languages
( small print – “not necessarily in the same way” )
2002 2005 2007 2009
Visual Basic 10
11
5
Visual Basic 10 Additions
C# 4.0
22
7
C# 4.0 Additions
Combined Additions
33
Dynamic Programming in VS 2008
Many places in .NET where we need to interact with “dynamic objects”
Reflection over .NET typesIDispatch invocation of COM typesIntegrating with from .NET DLR language typesIntegrating with the HTML DOM in Silverlight
TodaySome of this work is done in languagesSome of it in APIsNo consistent way of dealing with these scenarios
Dynamic Programming in VS 2008( taking Reflection as one example )
Compiler
Generates reflection-based goo
Compiler
Does not generate anything Does not generate anything
Dynamic Programming in VS 2010
Generated CodeUses System.Dynamic
Compiler Compiler
Like object but with dynamic method resolution & dispatch
Plain CLR Plain CLR Object?Object?
IDispatchIDispatchCOM COM
object?object?Implementation of Implementation of IDynamicObject?IDynamicObject?
Run-Run-timetimetype?type?
12
Dynamic types in C# 4, VB 10
Variance with Generic Types
Applies to generic interfaces and delegatesUsing interfaces as an example;
Access through a “base Access through a “base interface”interface”
Access through a “derived Access through a “derived interface”interface”
NB: Snippets compile but (intentionally) throw at runtime in VS2008 here
Strings are objects?Strings are objects?
Variance with Generic TypesConcrete Examples
NB: Snippets compile but (intentionally) throw at runtime in VS2008 here
Strings are objects?Strings are objects?
Safe if the caller cannot pass object references to the implementation
Safe if the implementation cannot pass object references to the caller
Variance with Generic Types
New syntax in C# 4 and VB 10 to indicate how a generic parameter is used by the interface
16
Variance in generic types
COM Interoperability in VS 2008
Usual scheme for working with COM types
COM TLB or DLL
Visual Studio ortlbimp.exe convertsall contained types,interfaces, etc.
Interop Assembly
ProgId()CoClass()...
.NETCode
ReferenceInterop assembly needs also deploying.Can be painful.Can be more painful for Primary Interop Assemblies (PIAs)Can be more painful for Office PIAs.
COM Interoperability in VS 2010
Revised scheme for working with COM types
Compiler option to copy COM interop typesused by code into output assemblyInterop
Assembly
.NETCode
Reference
Type 3Type 3Type 4Type 4
Type 1Type 1
Type 2Type 2
Type 1Type 1Type 2Type 2Type 3Type 3Type 4Type 4
ResultingAssembly
COM Interoperability in C# 4
COM code is littered with VARIANT typesespecially code written in VB or targetting VB
With Visual Studio < 2010Generated interop code used object for VARIANT
With Visual Studio 2010Choose to embed interop code in assemblySignatures are rewritten to use dynamic rather than object
20
COM Interoperability
Format of the session
11
22
33
Visual F#
Shipping for the first time in Visual Studio 2010
Session at 14:00 on Thursday“Taking efficiency one step further – F#”Oliver Sturm
References
“C# Futures”“VB Futures”“The Future of C#” “Future Directions for Visual Basic”
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS,
IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.