Getting Ready for Visual Studio 2005 London, October 19th 2005
So What’s New in Visual Studio ? Mike Pelton (Mike.Pelton@Microsoft.com) Mike Taulty (MTaulty@Microsoft.com) Developer and Platforms Group Microsoft Ltd
Housekeeping Launch Tour Caveats London, November 14th http://www.microsoft.com/uk/msdn Caveats We’re only scratching the surface These are brutally edited highlights Team System is a major topic in its own right
Agenda 18:30 Language and Framework Changes Mike<P> 19:00 IDE Enhancements Mike<T> 19:30 Break 20:00 What’s new in Windows Forms 20:30 What’s new in ASP.NET
Team System breaks down the barriers Developer Solution Architect Infrastructure Architect Tester Project Manager It’s not just about the developer anymore. Applications are so complex these days, that a single development project involves a number of different roles across the entire IT organization. BUILD Further, modern teams are: Geographically distributed More specialized than ever before Increased specialization leading to pockets of information More engagement of business people Shorter cycles to act Importance of the “abilities” Communication has never been more important End User
Visual Studio Team System Process and Architecture Guidance Visual Studio Industry Partners Visual Studio Team Architect Visual Studio Team Developer Visual Studio Team Test Application Designer Dynamic Code Analyzer Load Testing Logical Infra. Designer Static Code Analyzer Manual Testing Deployment Designer Code Profiler Test Case Management Unit Testing Code Coverage Class Designer Visio and UML Modeling Team Architect Highlight Team Foundation Client (includes CAL) Visual Studio Professional Edition Visual Studio Team Foundation Change Management Reporting Integration Services Big Build Work Item Tracking Project Site Project Management
Language Enhancements: An Introduction to Generics Demo Language Enhancements: An Introduction to Generics
Generics public class List { private object[] elements; private int count; public void Add(object element) { if (count == elements.Length) Resize(count * 2); elements[count++] = element; } public object this[int index] { get { return elements[index]; } set { elements[index] = value; } public int Count { get { return count; } public class List<T> { private T[] elements; private int count; public void Add(T element) { if (count == elements.Length) Resize(count * 2); elements[count++] = element; } public T this[int index] { get { return elements[index]; } set { elements[index] = value; } public int Count { get { return count; } List<int> intList = new List<int>(); intList.Add(1); // No boxing intList.Add(2); // No boxing intList.Add("Three"); // Compile-time error int i = intList[0]; // No cast required List intList = new List(); intList.Add(1); // Argument is boxed intList.Add(2); // Argument is boxed intList.Add("Three"); // Should be an error int i = (int)intList[0]; // Cast required List intList = new List(); intList.Add(1); intList.Add(2); intList.Add("Three"); int i = (int)intList[0];
Generics Public Class List Private elements() As Object Private mCount As Integer Public Sub Add(element As Object) If (mCount = elements.Length) Then _ Resize(mCount * 2) mCount += 1 elements(mCount) = element End Sub Default Public Property i(index As Integer) As Object Get Return elements(index) End Get Set elements(index) = value End Set End Property Public Property Count() As Integer Get : Return mCount : End Get End Class Public Class List(Of ItemType) Private elements() As ItemType Private count As Integer Public Sub Add(element As ItemType) If (count = elements.Length) Then _ Resize(count * 2) count += 1 elements(count) = element End Sub Public Property default(index As Integer) As ItemType Get : Return elements(index) : End Get Set : elements(index) = value : End Set End Property Public Property Count As Integer Get : Return count : End Get End Class Dim intList As New List(Of Integer) intList.Add(1) ‘ No boxing intList.Add(2) ‘ No boxing intList.Add("Three") ‘ Compile-time error int i = intList(0) ‘ No cast required Dim intList As New List intList.Add(1) intList.Add(2) intList.Add("Three") Dim i As Integer = intList(0) List intList = new List() intList.Add(1) ‘ Argument is boxed intList.Add(2) ‘ Argument is boxed intList.Add("Three") ‘ Should be an error int i = CInt(intList(0)) ‘ Cast required
Generics Why generics? How are C# generics implemented? Type checking, no boxing, no downcasts Reduced code bloat (typed collections) How are C# generics implemented? Instantiated at run-time, not compile-time Checked at declaration, not instantiation Work for both reference and value types Complete run-time type information
Generics Type parameters can be applied to Class, struct, interface, delegate types class Dictionary<K,V> {...} struct HashBucket<K,V> {...} interface IComparer<T> {...} delegate R Function<A,R>(A arg); Dictionary<string,Customer> customerLookupTable; Dictionary<string,List<Order>> orderLookupTable; Dictionary<string,int> wordCount;
Generics Type parameters can be applied to Class, struct, interface, delegate types Methods class Utils { public static T[] CreateArray<T>(int size) { return new T[size]; } public static void SortArray<T>(T[] array) { ... string[] names = Utils.CreateArray<string>(10); names[0] = "Jones"; ... Utils.SortArray(names);
Generics Type parameters can be applied to Class, struct, interface, delegate types Methods Type parameters can have constraints class Dictionary<K,V>: IDictionary<K,V> where K: IComparable<K> where V: IKeyProvider<K>, IPersistable, new() { public void Add(K key, V value) { ... } class Dictionary<K,V> { public void Add(K key, V value) { ... if (((IComparable)key).CompareTo(x) == 0) {...} } class Dictionary<K,V> where K: IComparable { public void Add(K key, V value) { ... if (key.CompareTo(x) == 0) {...} }
Generics Zero or one primary constraint Actual class, class, or struct Zero or more secondary constraints Interface or type parameter Zero or one constructor constraint new() class Link<T> where T: class {...} class Nullable<T> where T: struct {...} class Relation<T,U> where T: class where U: T {...}
Generics Collection classes Collection interfaces List<T> Dictionary<K,V> SortedDictionary<K,V> Stack<T> Queue<T> Collection classes Collection interfaces Collection base classes Utility classes Reflection IList<T> IDictionary<K,V> ICollection<T> IEnumerable<T> IEnumerator<T> IComparable<T> IComparer<T> Collection<T> KeyedCollection<T> ReadOnlyCollection<T> Nullable<T> EventHandler<T> Comparer<T>
With thanks to Kit George and GotDotNet Demo Generics Performance With thanks to Kit George and GotDotNet
Iterators foreach relies on “enumerator pattern” GetEnumerator() method foreach makes enumerating easy But enumerators are hard to write! foreach (object obj in list) { DoSomething(obj); } Enumerator e = list.GetEnumerator(); while (e.MoveNext()) { object obj = e.Current; DoSomething(obj); }
Iterators public class ListEnumerator : IEnumerator { List list; int index; internal ListEnumerator(List list) { this.list = list; index = -1; } public bool MoveNext() { int i = index + 1; if (i >= list.count) return false; index = i; return true; public object Current { get { return list.elements[index]; } public class List { internal object[] elements; internal int count; public IEnumerator GetEnumerator() { return new ListEnumerator(this); } public class List { internal object[] elements; internal int count; public IEnumerator GetEnumerator() { for (int i = 0; i < count; i++) { yield return elements[i]; }
public IEnumerator GetEnumerator() { return new __Enumerator(this); } private class __Enumerator : IEnumerator { object current; int state; public bool MoveNext() { switch (state) { case 0: current = "Hello"; state = 1; return true; case 1: current = "World"; state = 2; return true; default: return false; public object Current { get { return current; } Iterators Method that incrementally computes and returns a sequence of values yield return and yield break Must return IEnumerator or IEnumerable public class Test { public IEnumerator GetEnumerator() { yield return "Hello"; yield return "World"; }
Iterators public class List<T> { public IEnumerator<T> GetEnumerator() { for (int i = 0; i < count; i++) yield return elements[i]; } public IEnumerable<T> Descending() { for (int i = count - 1; i >= 0; i--) public IEnumerable<T> Subrange(int index, int n) { for (int i = 0; i < n; i++) yield return elements[index + i]; List<Item> items = GetItemList(); foreach (Item x in items) {...} foreach (Item x in items.Descending()) {...} foreach (Item x in Items.Subrange(10, 20)) {...}
Demo Iterators
Partial Types public partial class Customer { private int id; private string name; private string address; private List<Orders> orders; } public class Customer { private int id; private string name; private string address; private List<Orders> orders; public void SubmitOrder(Order order) { orders.Add(order); } public bool HasOutstandingOrders() { return orders.Count > 0; public partial class Customer { public void SubmitOrder(Order order) { orders.Add(order); } public bool HasOutstandingOrders() { return orders.Count > 0;
Partial Types in VB Single Type in Multiple Files Used to separate designer gen into another file Factor implementation Public Class Form1 Inherits Windows.Forms.Form ‘ Your Code End Class Partial Class Form1 ‘ Designer code Sub InitializeComponent() ‘ Your controls End Sub
Static Classes Only static members Cannot be used as type of variable, parameter, field, property, … Examples include System.Console, System.Environment public static class Math { public static double Sin(double x) {...} public static double Cos(double x) {...} ... }
Property Accessors Different accessor accessibility One accessor can be restricted further Typically set {…} more restricted public class Customer { private string id; public string CustomerId { get { return id; } internal set { id = value; } }
Accessor Accessibility Granular accessibility on Get and Set Forces calls to always use get, set Easy way to enforce validation Property Salary() As Integer Get Return mSalary End Get Private Set( value As Integer) If value < 0 Then Throw New Exception(“Mistake”) End If End Set End Property
And Relax…
With thanks to Joe Stegman for the sample code on WindowsForms.NET Demo Windows Forms 2.0 With thanks to Joe Stegman for the sample code on WindowsForms.NET
Data Binding and the New Grid Demo Data Binding and the New Grid With thanks to Michael Weinhardt’s MSDN “Wonders of Windows Forms” Column
“ClickOnce” Deployment Demo “ClickOnce” Deployment
And Relax…
© 2004 Microsoft Corporation. All rights reserved © 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.