1 / 30

Visual Basic 2008 – What’s new

Visual Basic 2008 – What’s new. André Obelink, MCSD – MVP MarYor | software & consultancy www.vbcentral.nl | www.obelink.com | www.maryor.nl. Me.About.ToString (). MarYor | software & consultancy Auteur van artikelen en boeken..

esben
Télécharger la présentation

Visual Basic 2008 – What’s new

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic 2008 – What’snew André Obelink, MCSD – MVP MarYor | software & consultancywww.vbcentral.nl | www.obelink.com | www.maryor.nl

  2. Me.About.ToString() • MarYor | software & consultancy • Auteur van artikelen en boeken.. • Geschreven voor Microsoft .NET Magazine, PC Active,MSDN Magazine Europe, SDN Magazine, VB Magazine • Boek: Visual Basic 2005 – de Basis (9/2006) • Boek: Visual Basic Kookboek (3/2008) • Boek: Visual Basic 2008 – de Basis (verwacht 5/2008) • De andere persoon achter VBcentral.nl • VP Speakers Bureau INETA Europe • Microsoft MVP voor Visual Basic sinds 2006

  3. Wat niet aan de orde komt… • Diverse uitbreidingen binnen VS2008 IDE • Quality tools • Uitbreidingen ten behoeve van WPF applicaties • Uitbreidingen ten behoeve van webapplicaties • Reporting: nieuwe Report Projects • MSBuild: multi-targetting, multiple processors • ……. • http://msdn2.microsoft.com/en-us/library/bb386063.aspx

  4. Wat wel aan de orde komt… • Performance VB2008 ten opzichte van VB2005 • IntellisenseEverywhere • LanguageIntegrated Query (LINQ) • LINQ to Objects, LINQ to SQL en LINQ to XML • En de taaluitbreidingen die LINQ mogelijk maakt… Type Infering, Object Initializers, Anonymous types, Extensionmethods, LambdaExpressions, … • XML Data Type

  5. Performance VB2008 ↔VB2005 Bron: Lisa Feigenbaum (VB team). Testmachine: Windows XP, Dual Core Pentium, 3.0 Ghz, 1 GB RAM • Verdereperformance verbeteringen • - Debugger, projecten laden, …

  6. Intellisense • Intellisense ‘everywhere’ • Performance sterk verbeterd • Intellisence voor JavaScript, CSS en XML literals • Transparant met CTRL toets • onderliggende code zichtbaar • VB: filtert het resultaat, waardoor lijst compacter • VB: LINQ en Intellisense + tooltip hints

  7. Visual Basic 9.0 – Design Goals • Vereenvoudig het werken met data • Integratie van query- en transformatie opdrachten • Universele manier van ‘quering’ van objecten, relationele data en XML data • Vereenvoudig het werken met XML • Breng structuur in documenten zonder schema • Maak creëren van XML documenten makkelijker • Vereenvoudig toegang tot XML elementen

  8. LanguageINtegrated Query (LINQ) Overige… C# VB .NET Language-Integrated Query Databronnen die LINQ ondersteunen LINQ binnen ADO.NET LINQ To XML LINQ To Objects LINQ To Datasets LINQ To Entities LINQ To SQL <boek> <titel/> <auteur/> </boek> Objecten Relationele data XML

  9. Demo LanguageIntegrated Query

  10. De ‘magie’ achter LINQ Dim query = Fromproc In Process.GetProcesses _ Whereproc.Threads.Count > 10 _ Select proc.ProcessName, proc.Threads.Count Dim query = Process.GetProcesses(). _ Where(Function(proc As Process) proc.Threads.Count > 10). _ Select(Function(proc As Process) _ New With{.ProcessName = proc.ProcessName, _ .Count =proc.Threads.Count}) Function _Filter1(proc As Process) As Boolean Return proc.Threads.Count > 10 Exit Function • Function _Projection1(proc As Process) As <AnonymousType> • Dim projection As New <AnonymousType> • projection.ProcessName = proc.ProcessName • projection.Count = proc.Threads.Count • Return projection • End Function

  11. Query Expressions

  12. Relationele data vandaag de dag Dim connectionAs New SqlConnection(…) • connection.Open() Dim cmd As New SqlCommand(“SELECT c.Name, c.Phone “ & _ “FROM Customers As c” & _ “WHERE c.City = @p0”) cmd.Parameters(“@p0”) = “London” Dim dr As DataReader = connection.Execute(cmd) Whiledr.Read() Dim name as String = dr.GetString(0) Dim telefoon as String = dr.GetString(1) Dim gebdatum As Date = dr.GetDateTime(2) End While • connection.Close() Queries tussen aanhalingstekens ‘looselybound’ argumenten ‘looselytyped’ resultaten Geen controle tijdens compileren

  13. Relationele Data met LINQ Public ClassCustomer … End Class Public ClassNorthwind InheritsDataContext Public PropertyCustomers As Table(Of Customer) … End Class Klassen beschrijven data Een Table is een soort collection ‘stronglytyped’ connection Dim db As New Northwind(…) Dim contact = Fromcust in db.Customers _ Wherecust.City = “London” Select cust.Name, cust.Phone For EachcustInfo in Contacts DoeIets(custInfo.Name, custInfo.Phone) Next Geïntegreerde query syntax ‘stronglytyped’ resultaten

  14. Demo Linq voor relationele data – Linq to SQL

  15. Even wennen aan de ‘SQL’ syntax Nodig voor IntelliSense • From komt voor Select Dim klanten = From klant in db.Customers _ Select klant.CustomerID, klant.CompanyName • Veel vrijheid bij bouwen query Bouw opdrachten ‘regel voor regel’ … Dim klanten = From klant in db.Customers _ Select klant.Name, klant.City, klant.ZIP _ Order By ZIP, _ Select Name, City … en over meerdere statements Dim klanten2 = From klant in klanten _ Whereklant.Name.StartsWith(“O”) _ Select klant.Name, klant.City Eventueel Select achterwege laten

  16. Even wennen aan de ‘SQL’ syntax Zogenaamde ‘GroupingKey’ • Expliciete aggregatie • Bevat ook operators voor hiërarchische data Dim klanten = Fromsodin db.SalesOrderDetails _ Group Bysod.SalesOrderHeader.CustomerID _ IntoOrderTotaal = Sum(sod.OrderQty * sod.UnitPrice) _ Select CustomerID, OrderTotaal Expliciete aggregatie ImportsSystem.Diagnostics Dim procs = Fromproc In Process.GetProcesses() _ Aggregate thread In proc.Threads _ IntoThreadPriorityGemiddelde = Average(thread.CurrentPriority) _ • Select LijstProcessen = proc.ProcessName, ThreadPriorityGemiddelde Groep bestaat al

  17. Demo Linq to XML – Maak XML

  18. Maak XML - vandaag de dag Dim doc As New XmlDocument Dim wns As XmlElement = doc.CreateElement("Werknemers") For Each werknemer As Werknemer In werknemers Ifwerknemer.Achternaam = "Jansen" Then Dim wn As XmlElement = doc.CreateElement("Werknemer") Dim BSN As XmlAttribute = doc.CreateAttribute("BSN") BSN.Value = werknemer.BSN : wn.Attributes.Append(BSN) Dim an As XmlElement = doc.CreateElement("Achternaam") an.InnerText = werknemer.Achternaam : wn.AppendChild(an) Dim voornaam As XmlElement = doc.CreateElement("Voornaam") voornaam.InnerText = werknemer.Voornaam : wn.AppendChild(voornaam) wns.AppendChild(wn) End If Next doc.AppendChild(wns) Imperatief model Geen geïntegreerde queries ‘Document centric’ Geheugen intensief <Werknemers> <Werknemer BSN=“12345”> <Achternaam>Jansen</Achternaam> <Voornaam>Piet</Piet> </Werknemer> … </Werknemers>

  19. LINQ to XML – Maak XML Declaratief model Dim xml As New XElement("Werknemers", _ From w In werknemers _ Wherew.Achternaam = "Jansen" _ Select New XElement("Werknemer", _ New XAttribute("BSN", w.BSN), _ New XElement("Achternaam", w.Achternaam), _ New XElement("Voornaam", w.Voornaam))) Geïntegreerde queries ‘Element centric’ Kleiner en sneller

  20. Demo Linq to XML – Geïntegreerde XML binnen VB

  21. Geïntegreerde XML binnen VB InfersXml.LinqXElement Dim werknemersxml = _ <Werknemers> <%= From w in werknemers _ Wherew.Voornaam = “Jan” _ Select <Werknemer> <Achternaam><%= w.Achternaam %></Achternaam> • <Voornaam><%= w.Voornaam %></Voornaam> </Werknemer> %> </Werknemers> Geen conceptuele barrière ‘Expression holes’ voor dynamische data / variabelen.

  22. Visual Basic 2008 - Features • Query expressions • XML literals • XML element access • Nullable types • Object initializers • Local type inference • Lambdaexpressions • Extensionmethods • Expression trees • Anonymous types • Ternary operator • Coalesce operator • Relaxed delegates • Partialmethods

  23. Tot de tijd op is… Taaluitbreidingen die LINQ mogelijk maken, maar ook erg handig zijn voor eigen gebruik!

  24. Extensionmethods • Uitbreiden van bestaande datatypen • Plaats methode in module en in zelfde namespace • Markeer methode met <Extension()> <Extension()> _ Public Function Omdraaien(ByValtekst As String) As String Dim karakterArray() As Char = tekst.ToCharArray() Array.Reverse(karakterArray) Return New String(karakterArray) End Function Dim strNaam As String = “André” Debug.PrintstrNaam.Omdraaien() -------------- Resultaat érdnA

  25. Object Initializers • Specificieer eigenschappen bij instantiëren • Is anders dan een overloaded Sub New() • Gebruik With {.eigenschapnaam = ….} Public Class Werknemer Public Property BSN() As String …. End Property …. End Class Dim werknemer As New Werknemer() With {.BSN = “123”} of … Dim bestand As New FileInfo(“c:\test.txt”) _ With {.IsReadOnly = True, _ .CreationTime = Now}

  26. Anonymous Types • Definieer + instantieer objecten ‘on the fly’ • … dit is waar LINQ op gebaseerd is... Dim boek = New With {.Titel = "Visual Basic Kookboek", _ .Auteur = "André Obelink", _ .ISBN = 9789043014878} boek.Titel &= " - Luxe Editie"

  27. LambdaExpressions • Functiedefinitie binnen een andere functie • lambda expressies zijn ook als argument te gebruiken • soort instantie van een delegate Dim woordenLijst As New List(Of String) woordenLijst.Add("een") : woordenLijst.Add("twee") woordenLijst.Add("vier") : woordenLijst.Add("zes") Dim DrieLetterWoorden = Function(s As String) s.Length = 3 Dim lijst = woordenLijst.FindAll(DrieLetterWoorden) For Each getal In lijst MessageBox.Show(getal) Next Dim Verdubbel = Function(Getal As Integer) Getal * 2 MessageBox.Show(Verdubbel(5).ToString) MessageBox.Show(Verdubbel(13).ToString)

  28. Visual Basic 2008 – Extra’s • Refactor! • Gratis Visual Studio Add-In van DevExpress • Geschikt voor Visual Basic 2003 – 2008 • Veel nieuwe features (>15), enkele alleen VB • Visual Basic Power Packs 3.0  VB6 upgrade • PrintForm, Printer CompatibilityLibrary • Line en Shape Controls • InteropForms Toolkit 2.0  MDI + User controls • DataRepeaterControl

  29. Vragen? e-mail: andre@obelink.com web: www.obelink.com | www.maryor.nl

  30. HEROEShappen {here} LaunchKit

More Related