200 likes | 482 Views
TL54. TL54: Natural Interop With Silverlight, Office, And Python In Microsoft Visual C# And Microsoft Visual Basic . Alex Turner C# Compiler Program Manager Microsoft Corporation. Natural Interop With Diverse Object Models.
E N D
TL54 TL54: Natural Interop With Silverlight, Office, And Python In Microsoft Visual C# And Microsoft Visual Basic Alex Turner C# Compiler Program Manager Microsoft Corporation
Natural Interop With Diverse Object Models • C# and Visual Basic were designed to work great with .NET’s strongly-typed libraries. • However, there are many other object models out there that rely on specific features from their original target language! C# Visual Basic HTML DOM .NET BCL COM Python Libs
HTML DOMExpects Dynamic Dispatch from JScript • JScript: var loc = new VELatLong(latitude, longitude); var pin = map.AddPushpin(loc); pin.SetTitle(title); pin.SetDescription(description); map.SetCenterAndZoom(loc, 7); • C# 3.0 (Silverlight): ScriptObject loc = win.CreateInstance( "VELatLong", latitude, longitude) ScriptObject pin = (ScriptObject)map.Invoke("AddPushpin", loc); pin.Invoke("SetTitle", title); pin.Invoke("SetDescription", description); map.Invoke("SetCenterAndZoom", loc, 7);
COMExpects Named & Optional Params from VBA • VBA: • VBA: • Selection.PasteSpecialLink:=True • Selection.PasteSpecialLink:=True • VB.NET: • word.Selection.PasteSpecial(Link:=True) • C# 3.0: • object missing = Type.Missing; • object link = true; • word.Selection.PasteSpecial( • ref missing, ref link, ref missing, • ref missing, ref missing, ref missing, • ref missing);
Python LibrariesExpects Dynamic Dispatch from Python • Python: • import random • random.shuffle(items) • C# 3.0: • var source = engine. • CreateScriptSourceFromFile(@"lib\random.py"); • var scope = engine.CreateScope(); • source.Execute(scope); • scope.SetVariable("items", items); • var source1 = engine.CreateScriptSourceFromString( • "random.shuffle(items)"); • source1.Execute(scope);
demo SilverlightHTML DOM Interop
Natural Interop With HTML DOMIn C# 4.0 • JScript: var loc = new VELatLong(latitude, longitude); var pin = map.AddPushpin(loc); pin.SetTitle(title); pin.SetDescription(description); map.SetCenterAndZoom(loc, 7); • C# 4.0 (Silverlight): dynamic loc = win.New.VELatLong(latitude, longitude) var pin = map.AddPushpin(loc); pin.SetTitle(title); pin.SetDescription(description); map.SetCenterAndZoom(loc, 7);
Natural Interop With HTML DOMIn VB 10 • JScript: var loc = new VELatLong(latitude, longitude); var pin = map.AddPushpin(loc); pin.SetTitle(title); pin.SetDescription(description); map.SetCenterAndZoom(loc, 7); • VB 10 (Silverlight): Dim loc As Object = win.New.VELatLong(latitude, longitude) Dim pin = map.AddPushpin(loc) pin.SetTitle(title) pin.SetDescription(description) map.SetCenterAndZoom(loc, 7)
demo OfficeCOM Interop
Natural Interop With COMIn C# 4.0 • VBA: • Selection.PasteSpecialLink:=True • VB.NET: • word.Selection.PasteSpecial(Link:=True) • C# 4.0: • word.Selection.PasteSpecial(Link: true);
demo IronPythonUsing Dynamic Language Libraries
Natural Interop With Python LibsIn C# 4.0 • Python: • import random • random.shuffle(items) • C# 4.0: dynamic random = python.UseFile("random.py"); random.shuffle(items);
Natural Interop With Python LibsIn VB 10 • Python: • import random • random.shuffle(items) • VB 10: Dim random As Object = python.UseFile("random.py") random.shuffle(items)
Natural Interop With Diverse Object Models • C# 4.0 and Visual Basic 10 have added features expected by other object models: • Named/optional parameters and “omit ref” in C# to support COM • Dynamic dispatch in VB and C# to supportthe HTML DOMand Python libraries C# Visual Basic .NET BCL HTML DOM COM Python Libs
Online Resources • C# Future Download Page: • http://code.msdn.microsoft.com/csharpfuture • SilverlightStarter project available in the CSharpDynamicSamplesdownload • VB Future Download Page: • http://code.msdn.microsoft.com/vbfuture • IronPython CTP Release: • http://go.microsoft.com/fwlink/?LinkId=129196
Related Sessions • Upcoming sessions: • TL12: Future Directions for Microsoft Visual Basic • Paul Vick • Tue 10/28 | 5:15 PM-6:30 PM | 406A • TL57: A Panel on the Future of Programming Languages • G. Bracha, D. Crockford, A. Hejlsberg, E. Meijer, W. Schulte, J. Siek • Wed 10/29 | 10:30 AM-11:45 AM | 403AB • TL16-R: The Future of C# • Anders Hejlsberg • Repeat: Wed 10/29 | 3:00 PM-4:15 PM | 502A • Past sessions to watch online: • TL10: Deep Dive: Dynamic Languages in .NET • Jim Hugunin
Evals & Recordings Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
Q&A Please use the microphones provided
© 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.