Download - Visual Basic 2008 Tips and Tricks
Visual Basic 2008 Tips and TricksLisa FeigenbaumProgram ManagerMicrosoft Visual Studio Languageshttp://blogs.msdn.com/[email protected]
VB 2008 Tips and Tricks
• Session Objectives• Learn language & IDE productivity features• Gain tips, tricks, best practices & answers
to FAQs• Agenda• IDE Improvements• New VB Refactorings & IntelliSense• Tips for writing LINQ queries• Using XML in VB 2008
• “Stop highlighting my snippets”• “Add my Imports statements for me”• And more…
• Performance• Large solutions, web apps, stepping,
first-time intelliSense, error list, editor responsivenesshttp://blogs.msdn.com/vbteam/archive/tags/Performance/default.aspx
You asked. We listened!
DemoIDE Improvements
Code just like you think!
• Refactor! for VB• Visual Studio Plug-in, available
FREE on MSDN• Partnership with Developer Express, Inc.• Total: 16 for VB 2005, 14 more for VB 2008
• Six Refactorings in C# 2005 & 2008:• Rename• Extract Method• Remove/Reorder parameters• Promote Local• Extract Interface• Encapsulate Field
VB Refactorings in 2005
1. Reorder Parameters 2. Surrounds With 3. Encapsulate field 4. Reverse Conditional 5. Simplify expression 6. Move initialization
to declaration 7. Split initialization
from declaration 8. Move declaration
near reference
8. Extract Method 9. Extract Property 10.Create Overload 11.Introduce Local 12.Introduce constant 13.Inline Temp 14.Replace Temp with
Query 15.Split Temporary
Variable
For VB 8.0: 17.Create With
Statement 18.Inline With
Statement 19.Widen Scope 20.Extract Interface 21.Move Type to File 22.Introduce Parameter 23.Remove Unused
Parameter 24.Method to Property 25.Property to
Method(s)
For VB 9.0::26.Extract XML
Literals to Resource
27.Make Explicit 28.Make Explicit
(and Name Anonymous Type)
29.Make Implicit 30.Name
Anonymous Type
VB Refactorings in 2008
DemoRefactor! 2008
• Benefits• Less typing• Less memorizing of names and grammar• Fewer errors
• IntelliSense Everywhere• New line, Expressions, Keywords, Variables
• IntelliSense Features• Transparency• Filter-As-You-Type• Documentation: Keyword & Syntax tips
Getting Productive with IntelliSense
DemoGetting Productive with IntelliSense in VB 2008
11
LINQ
Objects
<book> <title/> <author/> <year/> <price/></book>XM
L
.NET Language Integrated Query
C# 3.0 VB 9.0 Others…
Relational
LINQ toObjects
LINQ toSQL
LINQ toXML
LINQ toEntities
LINQ toDataSets
Language INtegrated Query
Dim c As New SqlConnection(…)c.Open()Dim cmd As SqlCommand( _ "SELECT c.Name, c.Phone “ & _ "FROM Customers c” & _ "WHERE c.City = @p0")cmd.Parameters("@p0“) = "London"Dim dr As DataReader= c.Execute(cmd)While (dr.Read()) Dim name As String = r.GetString(0) Dim phone As String= r.GetString(1) Dim date As DateTime = r.GetDateTime(2)End Whiler.Close()
Queries in quotes
Loosely bound arguments
Loosely typed result sets
Querying Relational DataAccessing data the hard way
Public Class Customer …
Public Class Northwind Inherits DataContext
Public Property Customers As Table(Of Customer)
…End Class
Dim db As New Northwind(…)Dim contacts = _ From cust in db.Customers _ Where cust.City = "London" Select cust.Name, cust.Phone
For Each custInfo in contacts ColdCall(custInfo.Name, custInfo.Phone)Next
Classes describe data
Compile-time checking
Integrated query syntax
Strongly typed results
Tables are like collections
Accessing Data with LINQQuerying Relational Data
DemoLINQ Tips & Tricks
LINQ Demo SummaryBest Practices, Gotchas, FAQs• IntelliSense• Query result shape• Aliasing columns• Composing queries• Ordering operators• Designing for Performance• The Aggregate operator• Understanding Deferred Execution• Debugging• Running SQL from VB/C#
DemoSay it in XML!
XML in VS 2008 Topics Covered
• Inline XML in VB• Embedded Expressions• XLinq• Axis Properties• Children, Descendants, Attributes
• XML IntelliSense for VB• XML Case Sensitivity• Multi-Line Strings
Summary
• What We’ve Seen• IDE Improvements• Refactor!• New IntelliSense• LINQ• Integrated XML Support
• Call to Action• Use the demo code. Try it out.• Look up the resources.• Tell us your feedback & what you want to
see in the future.
Resources
Visual Basic Developer Centerhttp://msdn.com/vbasic
Blogshttp://blogs.msdn.com/vbteam (VB Team)http://blogs.msdn.com/bethmassi (Beth Massi)
Refactor!http://msdn.microsoft.com/vbasic/bb693327
Visual Basic Forumshttp://forums.msdn.microsoft.com/en-US/tag/visualbasic/forums/
Connecthttps://connect.microsoft.com/VisualStudio