Pro VB 2008 and the .NET 3.5 Platform
Total Page:16
File Type:pdf, Size:1020Kb
Pro VB 2008 and the .NET 3.5 Platform Andrew Troelsen Pro VB 2008 and the .NET 3.5 Platform Copyright © 2008 by Andrew Troelsen All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-59059-822-1 ISBN-10 (pbk): 1-59059-822-9 ISBN-13 (electronic): 978-1-4302-0200-4 ISBN-10 (electronic): 1-4302-0200-9 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Ewan Buckingham Technical Reviewer: Andy Olsen Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Production Director and Project Manager: Grace Wong Senior Copy Editor: Ami Knox Copy Editor: Nicole Flores Associate Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Dina Quan Artist: April Milne Proofreaders: April Eddy, Linda Seifert, Liz Welch Indexer: Broccoli Information Management Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precau- tion has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Source Code section. You may need to answer questions pertaining to this book in order to successfully download the code. To my Grandmother, Maxine. Hey Lady! I honestly don’t think I’ve ever met a stronger woman. You are a rock, Gerta. Love ya. Contents at a Glance About the Author. xix About the Technical Reviewer . xix Acknowledgments. xx Introduction and Welcome. xxi PART 1 ■ ■ ■ Introducing Visual Basic 2008 and the .NET Platform ■CHAPTER 1 The Philosophy of .NET . 3 ■CHAPTER 2 Building Visual Basic 2008 Applications . 35 PART 2 ■ ■ ■ Core VB Programming Constructs ■CHAPTER 3 VB 2008 Programming Constructs, Part I . 65 ■CHAPTER 4 VB 2008 Programming Constructs, Part II. 103 ■CHAPTER 5 Designing Encapsulated Class Types . 129 ■CHAPTER 6 Understanding Inheritance and Polymorphism . 173 ■CHAPTER 7 Understanding Structured Exception Handling . 207 ■CHAPTER 8 Understanding Object Lifetime . 233 PART 3 ■ ■ ■ Advanced VB Programming Constructs ■CHAPTER 9 Working with Interface Types . 255 ■CHAPTER 10 Collections, Generics, and Nullable Data Types . 291 ■CHAPTER 11 Delegates, Events, and Lambdas. 327 ■CHAPTER 12 Operator Overloading and Custom Conversion Routines . 359 ■CHAPTER 13 VB 2008–Specific Language Features . 383 ■CHAPTER 14 An Introduction to LINQ. 409 iv PART 4 ■ ■ ■ Programming with .NET Assemblies ■CHAPTER 15 Introducing .NET Assemblies . 437 ■CHAPTER 16 Type Reflection, Late Binding, and Attribute-Based Programming . 483 ■CHAPTER 17 Processes, AppDomains, and Object Contexts. 517 ■CHAPTER 18 Building Multithreaded Applications. 537 ■CHAPTER 19 .NET Interoperability Assemblies . 571 PART 5 ■ ■ ■ Introducing the .NET Base Class Libraries ■CHAPTER 20 File and Directory Manipulation . 607 ■CHAPTER 21 Introducing Object Serialization. 633 ■CHAPTER 22 ADO.NET Part I: The Connected Layer . 653 ■CHAPTER 23 ADO.NET Part II: The Disconnected Layer . 705 ■CHAPTER 24 Programming with the LINQ APIs. 759 ■CHAPTER 25 Introducing Windows Communication Foundation . 795 ■CHAPTER 26 Introducing Windows Workflow Foundation . 843 PART 6 ■ ■ ■ Desktop Applications with Windows Forms ■CHAPTER 27 Introducing Windows Forms . 883 ■CHAPTER 28 Rendering Graphical Data with GDI+ . 929 ■CHAPTER 29 Programming with Windows Forms Controls. 983 PART 7 ■ ■ ■ Desktop Applications with WPF ■CHAPTER 30 Introducing Windows Presentation Foundation and XAML. 1047 ■CHAPTER 31 Programming with WPF Controls . 1103 ■CHAPTER 32 WPF 2D Graphical Rendering, Resources, and Themes . 1167 PART 8 ■ ■ ■ Building Web Applications with ASP.NET ■CHAPTER 33 Building ASP.NET Web Pages . 1215 ■CHAPTER 34 ASP.NET Web Controls, Themes, and Master Pages . 1261 ■CHAPTER 35 ASP.NET State Management Techniques . 1297 INDEX. 1331 v Contents About the Author. xix About the Technical Reviewer . xix Acknowledgments. xx Introduction and Welcome. xxi PART 1 ■ ■ ■ Introducing Visual Basic 2008 and the .NET Platform ■CHAPTER 1 The Philosophy of .NET . 3 Understanding the Previous State of Affairs . 3 The .NET Solution. 6 Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS) . 6 What Visual Basic 2008 Brings to the Table . 7 Additional .NET-Aware Programming Languages. 9 An Overview of .NET Assemblies . 10 Understanding the Common Type System . 16 Understanding the Common Language Specification . 19 Understanding the Common Language Runtime . 21 The Assembly/Namespace/Type Distinction. 22 Using ildasm.exe . 27 Using Lutz Roeder’s Reflector. 30 Deploying the .NET Runtime . 30 The Platform-Independent Nature of .NET . 31 Summary . 32 ■CHAPTER 2 Building Visual Basic 2008 Applications . 35 The Role of the .NET Framework 3.5 SDK. 35 The VB 2008 Command-Line Compiler (vbc.exe). 36 Building VB 2008 Applications Using vbc.exe. 37 Working with vbc.exe Response Files . 40 Building .NET Applications Using SharpDevelop. 43 Building .NET Applications Using Visual Basic 2008 Express . 46 vi ■CONTENTS vii Building .NET Applications Using Visual Studio 2008 . 47 The Role of the Visual Basic 6.0 Compatibility Assembly . 59 A Partial Catalog of Additional .NET Development Tools . 61 Summary . 61 PART 2 ■ ■ ■ Core VB Programming Constructs ■CHAPTER 3 VB 2008 Programming Constructs, Part I . 65 The Role of the Module Type . 65 The Role of the Main.