What Can Visual Studio 2008 Do For You?
Download
Report
Transcript What Can Visual Studio 2008 Do For You?
Eric Vogel
Software Developer
A.J. Boggs & Company
What’s new?
New Projects for .NET 3.0 and 3.5
Framework build targeting
Javascript IDE enhancements
Built in Unit Testing!
New language additions to C# and VB
New Projects
Windows
WPF
Web
ASP.NET AJAX
WCF Service
Office
Office 2007
Workflow
Smart Device
Target .NET 2.0,3.0, and 3.5 Compact Frameworks.
Windows Mobile 5.0, 6.0 SDK as free download.
.NET 3.0
Windows Presentation Foundation (WPF)
Windows Forms replacement.
Controls are expressed in XAML.
Provides a more expressive UI layer for applications.
Windows Communication Foundation (WCF)
Bridges networking APIs (Web Services, .NET
Remoting,..) into one API.
Very configurable, supports multiple transport layers
such as http and tcp.
SOAP 1.1 and 1.2 complient.
.NET 3.0 (continued)
Work Flow (WF)
Allows graphical design of sequences and state
machines.
Good for expressing business processes.
Card Space
Security identification service that stores users
identification information.
WCF supports Card Space.
.NET 3.5
New language additions to C# 3.0 and VB .NET 9.0
LINQ
ASP .NET AJAX
WF support in WCF Services
Host Work Flow in a WCF Service
Framework build targeting
Compile projects to target a specific .NET Framework.
Supports .NET 2.0,3.0, and 3.5
Javascript IDE Enhancements
IntelliSense support added
Easier to debug code
Demo
Unit Testing
Only included in Pro and Team Editions.
Can create tests for Web, Desktop, and Mobile
applications.
Demo
New in C# and VB .NET
Implicitly typed local variables
Object intializers
Array initializers
Anonymous types
Extension Methods
Lambda Expressions
LINQ
Implicitly typed local variables
Variable declarator must have an intializer
Type is inferred by the initialization of the variable
Variable cannot be initialized to null
Examples:
C#
var foo = 5;
var bar = “Hello GLUG .net”;
var foobar = new List<int>();
VB
Dim foo = 5;
Dim bar = “Hello GLUG .net”;
Dim foobar = New List(Of Integer)
Object initialzers
Initialize properties and accessible members of an
object.
Nice substitute for overloaded constructors.
Can be embedded
Examples:
C#
var voyager = new Ship{Capacity=1000, Shields=200};
VB
Dim voyager = New Ship With {.Capacity = 1000,
.Shields = 200}
Implicitly typed arrays
The type of the array is determined by its initialized
content.
Examples:
C#
var scores = new[] { 50, 60, 70, 70, 80, 90, 100 };
VB
Dim scores() = { 50, 60, 70, 70, 80, 90, 100 }
Anonymous Types
Create objects with anonymous types.
Anonymous types inherit from Object.
Examples:
C#
var item = new { Id=10, ItemType="Game", Cost= 29.99 };
VB
Dim item = New With {.Id = 10, .ItemType = "Game", .Cost
= 29.99}
Extension Methods
Static method that extends an existing class.
Invoked as if it were an instance method of the class
being extended.
Shadowed by member methods of the extending class.
Only allowed access to public members of the
extending class.
Extension Methods (C# example)
Example:
public static class ExtensionMethods
{
public static bool GreaterThan(this int i, int n)
{
return i > n;
}
}
int num = 5;
num.GreaterThan(2);
// will return true, since 5 is greater than 2
Extension Methods (VB example)
Example:
Imports System.Runtime.CompilerServices
Public Module ExtensionMethods
<Extension()> _
Public Function GreaterThan(ByVal i As Integer, ByVal n As Integer) As Boolean
Return i > n
End Function
End Module
Dim num As Integer = 5
num.GreaterThan(2) ) ‘ will return true, since 5 is greater than 2
Lambda Expressions
C#
(input parameters) => { expression or statement block }
VB
Function(input parameters) expression or statement block
Provide a cleaner and more concise expression of
anonymous methods.
Parameters can be explicitly or implicitly typed.
Have a million and one uses!
Demo
LINQ
Language INtegration Query or LINQ introduces the
ability to query objects directly in the language.
Syntax is very similar to SQL.
Visual Studio 2008 currently has LINQ to SQL, LINQ
to XML and LINQ to Objects.
Demo of LINQ to Objects.
C# only additions
Collection Intializers
Automatic properties
Collection Initializers
Collection must implement IEnumerable.
Each item is added to the collection behind the scenes
by calling the Add method of the collection.
Examples:
List<string> names = new List<string> { “Eric”, “Jeff”, “Joe” };
List<int> scores = new List<int> { 50, 60, 70, 70, 80, 90};
Automatic Properties
More concise way to create a Property with a backing
field.
New default code snippet for prop in VS 2008.
Examples:
public int NumDays { get; set; }
public DateTime DueDate { get; set; }
VB .NET only additions
XML Literals
Relaxed Delegates
XML literals
XML is able to be used as a literal.
IntelliSense support, including schemas.
Tight integration with LINQ to XML.
Examples:
Dim products = <Products>
<Product name="CodeSmart">
<Id>20</Id>
</Product>
</Products>
Dim appConfig = <?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>
Relaxed Delegates
Methods no longer have to exactly match their method
delegate signatures.
Methods can have a derived type of what is defined in
the delegate as a return type (covariance).
Methods can be passed arguments with types that are
base classes of the arguments specified in the delegate
signature (contravariance).
Covariance Example
Public Class Record
End Class
Public Class Person
Inherits Record
End Class
Public Delegate Function RecordChanged(ByVal Id As Integer) As Record
Public Function GetChangedRecord(ByVal Id As Integer) As Record
Return New Record
End Function
Public Function GetChangedPerson(ByVal Id As Integer) As Person
Return New Person
End Function
Sub Main()
Dim changedPerson As RecordChanged = AddressOf GetChangedPerson
End Sub
Contravariance Example
Public Delegate Sub PersonSelected(ByVal Person)
Public Sub RecordSelected(ByVal Record)
End Sub
Sub Main()
'Contravariance
Dim personPicked As PersonSelected = AddressOf
RecordSelected
End Sub
Contact
[email protected]
http://ericvogel.com
Twitter - @vogelvision
References
Overview of C# 3.0
http://msdn.microsoft.com/enus/library/bb308966.aspx#csharp3.0overview_topic1
Overview of Visual Basic 9.0
http://msdn.microsoft.com/enus/library/ms364068(vs.80).aspx#vb9overview_topic1
Programming C# 3.0
Jesse Liberty & Donald Xie, O’Reily
The LINQ Project
http://msdn.microsoft.com/enus/netframework/aa904594.aspx