903 pro c 5 0 and the NET 4 5 framework, 6th edition

1.5K 378 0
903 pro c 5 0 and the  NET 4 5 framework, 6th edition

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

CYAN MAGENTA YELLOW BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® THE EXPERT’S VOICE® IN NET Troelsen Pro C# 5.0 and the NET 4.5 Framework RELATED Explore the NET universe on your own terms with Pro C# 5.0 and the NET 4.5 Framework From the very latest features to essential concepts, this book teaches you the ins and outs of the leading NET technology Led by an award-winning author who has been teaching the NET world since version 1.0, you’ll gain a deep understanding of the core aspects of the C# programming language together with the new features introduced with the release of NET 4.5 With Pro C# 5.0 and the NET 4.5 Framework, you'll learn: • Object-Oriented Programming with C# • The relationship between delegates, events and lambda expressions • Programming with the LINQ technology set • Multithreaded, parallel and asynchronous programming • Interacting with legacy code using the Dynamic Language Runtime • Communicating with relational databases using ADO.NET • Creating distributed systems using WCF • Modeling business processes using WF • Building desktop and web based user interfaces using WPF and ASP.NET Whether you’re an experienced coder moving to NET for the first time or are already writing applications using previous NET versions, Pro C# 5.0 and the NET 4.5 Framework will provide you with a comprehensive grounding in the new technology and serve as a complete reference throughout your coding career US $59.99 Shelve in NET ISBN 978-1-4302-4233-8 59 9 SIXTH EDITION User level: Intermediate–Advanced SOURCE CODE ONLINE Fourteen leading lights in Oracle Application Express share their favorite insights from the field 781430 242338 www.apress.com www.it-ebooks.info this print for content only—size & color not accurate 7.5 x 9.25 spine = 2.08" 1560 pages 750PPI For your convenience Apress has placed some of the front matter material after the index Please use the Bookmarks and Contents at a Glance links to access them www.it-ebooks.info Pro C# 5.0 and the NET 4.5 Framework Sixth Edition  Andrew Troelsen www.it-ebooks.info Pro C# and the NET 4.5 Framework, Sixth Edition Copyright © 2012 by Andrew Troelsen This work is subject to copyright All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher's location, in its current version, and permission for use must always be obtained from Springer Permissions for use may be obtained through RightsLink at the Copyright Clearance Center Violations are liable to prosecution under the respective Copyright Law ISBN-13 (pbk): 978-1-4302-4233-8 ISBN-13 (electronic): 978-1-4302-4234-5 Trademarked names, logos, and images may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made The publisher makes no warranty, express or implied, with respect to the material contained herein President and Publisher: Paul Manning Lead Editor: Ewan Buckingham Technical Reviewer: Andy Olsen Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel, Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh Coordinating Editors: Jessica Belanger, Christine Ricketts Copy Editors: Ralph and Vanessa Moore Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com For information on translations, please e-mail rights@apress.com, or visit 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 www.apress.com/bulk-sales Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com For detailed information about how to locate your book’s source code, go to www.apress.com/sourcecode www.it-ebooks.info This edition of the text is dedicated to the two most important people in my life First to my wife Mandy, who was crazy enough to bring up the idea of adoption Second, to my son Soren Wade Troelsen Words can’t express how much I love you However, I will say one thing: Grrrrrrawwwwhhhh! You can ask me about this when you get older www.it-ebooks.info Contents at a Glance  About the Author liii  About the Technical Reviewer liv  Acknowledgments lv  Introduction lvi  Part I: Introducing C# and NET Platform  Chapter 1: The Philosophy of NET  Chapter 2: Building C# Applications .39  Part II: Core C# Programming .71  Chapter 3: Core C# Programming Constructs, Part I 73  Chapter 4: Core C# Programming Constructs, Part II 121  Part III: Object-Oriented Programming with C# 161  Chapter 5: Understanding Encapsulation 163  Chapter 6: Understanding Inheritance and Polymorphism .213  Chapter 7: Understanding Structured Exception Handling 253  Chapter 8: Working with Interfaces 281  Part IV: Advanced C# Programming 319  Chapter 9: Collections and Generics 321  Chapter 10: Delegates, Events, and Lambda Expressions 359  Chapter 11: Advanced C# Language Features 399  Chapter 12: LINQ to Objects 439  Chapter 13: Understanding Object Lifetime 473  Part V: Programming with NET Assemblies .501  Chapter 14: Building and Configuring Class Libraries 503 iv www.it-ebooks.info  CONTENTS  Chapter 15: Type Reflection, Late Binding, and Attribute-Based Programming.555  Chapter 16: Dynamic Types and the Dynamic Language Runtime .599  Chapter 17: Processes, AppDomains, and Object Contexts 623  Chapter 18: Understanding CIL and the Role of Dynamic Assemblies 651  Part VI: Introducing the NET Base Class Libraries .695  Chapter 19: Multithreaded, Parallel, and Async Programming 697  Chapter 20: File I/O and Object Serialization 753  Chapter 21: ADO.NET Part I: The Connected Layer 801  Chapter 22: ADO.NET Part II: The Disconnected Layer 859  Chapter 23: ADO.NET Part III: The Entity Framework 927  Chapter 24: Introducing LINQ to XML 967  Chapter 25: Introducing Windows Communication Foundation 985  Chapter 26: Introducing Windows Workflow Foundation 1047  Part VII: Windows Presentation Foundation .1089  Chapter 27: Introducing Windows Presentation Foundation and XAML 1091  Chapter 28: Programming with WPF Controls 1157  Chapter 29: WPF Graphics Rendering Services 1223  Chapter 30: WPF Resources, Animations, and Styles .1267  Chapter 31: Dependency Properties, Routed Events, and Templates 1301  Part VIII: ASP.NET Web Forms 1335  Chapter 32: Introducing ASP.NET Web Forms 1337  Chapter 33: ASP.NET Web Controls, Master Pages, and Themes 1383  Chapter 34: ASP.NET State Management Techniques .1429  Index 1463 v www.it-ebooks.info Contents  About the Author liii  About the Technical Reviewer liv  Acknowledgments lv  Introduction lvi  Part I: Introducing C# and NET Platform  Chapter 1: The Philosophy of NET An Initial Look at the NET Platform Some Key Benefits of the NET Platform Introducing the Building Blocks of the NET Platform (the CLR, CTS, and CLS) .4 The Role of the Base Class Libraries What C# Brings to the Table Managed vs Unmanaged Code Additional NET-Aware Programming Languages Life in a Multilanguage World An Overview of NET Assemblies .9 The Role of the Common Intermediate Language 10 The Role of NET Type Metadata 13 The Role of the Assembly Manifest 14 Understanding the Common Type System .15 CTS Class Types 15 CTS Interface Types 16 vi www.it-ebooks.info  CONTENTS CTS Structure Types 16 CTS Enumeration Types 17 CTS Delegate Types 17 CTS Type Members 17 Intrinsic CTS Data Types 18 Understanding the Common Language Specification 19 Ensuring CLS Compliance 20 Understanding the Common Language Runtime .21 The Assembly/Namespace/Type Distinction 22 The Role of the Microsoft Root Namespace 25 Accessing a Namespace Programmatically 26 Referencing External Assemblies 27 Exploring an Assembly Using ildasm.exe 28 Viewing CIL Code 29 Viewing Type Metadata 30 Viewing Assembly Metadata (a.k.a the Manifest) 31 The Platform-Independent Nature of NET .31 A Brief Word Regarding Windows Applications 33 Building Windows Applications 34 The Role of NET Under Windows 35 Summary 37  Chapter 2: Building C# Applications .39 The Role of the NET Framework 4.5 SDK .39 The Developer Command Prompt 40 Building C# Applications Using csc.exe 40 Specifying Input and Output Targets 41 Referencing External Assemblies 43 vii www.it-ebooks.info  CONTENTS Referencing Multiple External Assemblies 44 Compiling Multiple Source Files 44 Working with C# Response Files 45 Building NET Applications Using Notepad++ 47 Building NET Applications Using SharpDevelop 48 Building a Simple Test Project 48 Building NET Applications Using Visual C# Express .51 Some Unique Features of Visual C# Express 52 Building NET Applications Using Visual Studio .52 Some Unique Features of Visual Studio 53 Targeting the NET Framework Using the New Project Dialog Box 54 Using the Solution Explorer Utility 54 The Class View Utility 57 The Object Browser Utility 58 Integrated Support for Code Refactoring 59 Code Snippets and Surround with Technology 62 The Visual Class Designer 63 The Integrated NET Framework 4.5 SDK Documentation System 67 Summary 70  Part II: Core C# Programming .71  Chapter 3: Core C# Programming Constructs, Part I 73 The Anatomy of a Simple C# Program 73 Variations on the Main() Method 75 Specifying an Application Error Code 76 Processing Command-Line Arguments 77 Specifying Command-Line Arguments with Visual Studio 78 An Interesting Aside: Some Additional Members of the System.Environment Class .79 viii www.it-ebooks.info ■ INDEX SQL queries, 954–955 updation, 952 connected and disconnected layers, 927–928 data and modeling section, 965–966 EDM, 929–931 designer-generated classes, 949–950 *.edmx file, 937–941 mapping details, 944 reshape, 941–944 source code generation, 947–949 view, *.edmx file data, 945–947 inventory schema, 930 LINQ queries, 928–929 NET data-access, 965–966 object context, 929–931 overview, 927 SQL queries, 929 Enumeration, 140 Events, 378 anonymous methods, 387 accessing local variables, 389–390 MyEventHandler method, 387 arguments, 384–386 event keyword, 379–380 generic EventHandler delegate, 386 hidden methods of, 380–381 incoming events, 381–383 registration, Visual Studio, 383–384 Extensible Application Markup Language (XAML), 1091 animation services definition, 1289–1290 discrete key frames, 1291–1292 event triggers, 1290–1291 Storyboards, 1290 with Visual Studio, 1148 Button’s Click Event implementation, 1151–1152 closed event implementation, 1153 GUI design, 1148–1150 Loaded Event implementation, 1150– 1151 testing, 1153 WPF documentation, 1154 Extension methods definition, 418 DisplayDefiningAssembly() method, 419 importing extension methods, 421 IntelliSense of, 421 InterfaceExtensions project, 422 invoking extension methods, 420 ReverseDigits() method, 419 F FunWithArrays application, 140 G Generic collections, 333 benefits, 333 custom generic methods, 349 overloading, 349 Swap method, 350–351 type parameters, interface of, 351–352 default keyword, 354–355 structures and classes, 353–354 System.Collections.Generic namespace, 338 type parameters constraints, 355 generic classes/structures, 335–336 generic interfaces, 337–338 generic members, 336 lack of operator, 357–358 where keyword, 356–357 Generics, 321 GetValue()/SetValue() properties, 1305–1306 Global assembly cache (GAC), 27, 511, 532–533 Graphics rendering services, 1223 brushes configuration in code, 1239–40 DrawingBrush and VisualBrush classes, 1236 ImageBrush, 1236 LinearGradientBrush and RadialGradientBrush, 1236 types, 1236 Visual Studio configuration, 1236–39 drawings and geometries, 1224, 1250 building a DrawingBrush, 1251–52 DrawingBrush, 1251 drawing-derived types, 1250 DrawingImage, 1251, 1253 DrawingVisual, 1251 painting with DrawingBrush, 1252–53 shape-derived types, 1251 expression design, 1254 as XAML, exporting file, 1254 InteractiveTeddyBear, 1256 leftEye and rightEar objects, 1258 immediate-mode graphics, 1223 1473 www.it-ebooks.info ■ INDEX Graphics rendering services (cont.) options, 1224 pens, 1240 retained-mode graphics, 1223 shapes, 1224 addings shapes to canvas, 1227–30 Ellipse class, 1225 FrameworkElement class, 1225 Line, 1225 MouseDown event, 1226 Path, 1225, 1232–34 Polygon, 1225 Polygons, 1231–32 Polyline, 1225 Polylines, 1231–32 properties, 1226 Rectangle, 1225 removing shapes from canvas, 1230–31 System.Windows.Shapes namespace, 1225 UIElement class, 1225 transformations, 1241 canvas data, 1243–45 LayoutTransform property, 1241 RenderingWithShapes project, 1242–43 RenderTransform property, 1241 types, 1241 visual layer, 1258 custom FrameworkElement, 1264 DrawingVisual class, 1259–62 FrameworkElement, 1262 GetVisualChild() method, 1263 hit-test operations, 1264–65 visual base class and derived child class, 1259 visuals, 1224 H Halting bubbling, 1315 Hypertext Markup Language (HTML) document structure, 1340–1341 form building, 1344–1346 roles, 1341–1342 IDEs, 1340 Visual Studio designer tools, 1342–1344 HyperText Transfer Protocol (HTTP), 1376 request/response cycle, 1337–1338 stateless protocol, 1338 I Implicitly typed local arrays, 134–135 Indexer method, 399 AddPerson() or GetPerson() method, 401 anonymous types, 423 definition, 424 internal representation, 425 limitations, 429 semantics of equality, 427–428 ToString() and GetHashCode() implementation, 426 custom classes and structures, 399 custom type conversions (see also Custom type conversions) explicit methods (see also Extension methods) Insert() method, 401 interface types, 404 with multiple dimensions, 403 operator overloading (see also Operator overloading) overloading indexer methods, 403 PersonCollection class configuration, 400 pointer types * and & operators, 433–434 -> operator, field access, 435 fixed keyword, 436–437 operators and keywords, 430 sizeof keyword, 437 stackalloc keyword, 435 unsafe keyword, 431–433 unsafe swap function, 434–435 SimpleIndexer application, 400 using string values, 401 this[] syntax, 400 Inheritance, 184–187, 213 adding sealed class, 224 ASP.NET, 1371–1372 base class/derived class casting rules, 240 as keyword, 242–243 explicit cast, 242 implicit cast, 241 is keyword, 243 basic mechanics of, 213 multiple base classes, 216 parent class specification, existing class, 214–216 sealed keyword, 224 containment/delegation, programming for 1474 www.it-ebooks.info ■ INDEX has-a relationship, 225 is-a relationship, 225 nested type definitions, 226–228 controlling base class creation with base keyword, 221, 223 protected keyword, 223–224 revising Visual Studio class diagrams, 218 System.Object class, 243 definition, 244 instance methods, 244 modified person class, testing, 249 overriding system.Object.Equals(), 247, 248 overriding System.Object.GetHashCode(), 248 overriding system.Object.ToString(), 247 root namespace, 246 static members of, 250 Interacts, ASP.NET HTTP request browser statistics, 1374 form data, 1355–1358 Hmethods, 1373 IsPostBack properties, 1375 members, 1372–1373 HTTP response HTML content, 1376 methods, 1375–1376 properties, 1375–1376 redirect, 1377 Interfaces, 281 custom, definition of, 284–286 explicit interface implementation, 296 Draw method, 296 Octagon type, 297–299 hierarchies, 299–300 IAdvancedDraw, 299 IDrawable, 299 multiple inheritance, 300–302 ICloneable Clone method, 308, 311 MemberwiseClone, 309, 312 Point, 308, 310 System.Guid, 310 IComparable Car class, 313 CompareTo return values, 314 custom properties and sort types, 317 definition, 313 multiple sort orders, 316–317 System.Array class, 314 IEnumerable and IEnumerator, 302 named iterator, 306–307 yield keyword, 305–306 implementation, 286–288 object level, invoking members, 288 as keyword, 289 is keyword, 290 structured exception handling, 289 as parameters, 291–293 as return values, 293 types, 281 vs abstract base classes, 282–284 abstract members, 281 Fork, 294 IDbConnection, 281 Knife, 294 PitchFork, 294 using Visual Studio, 295 Internet Information Services (IIS), 1338 IsPostBack properties, 1375 J Jagged array, 136 K Kaxaml, 1127–1128 L Lambda expressions, 390 FindAll method, 390 with multiple (or zero) parameters, 395 parameters of, 393 Predicate delegate type, 392 processing arguments within multiple statements, 394–395 retrofitting CarEvents, 396–397 Language Integrated Query (LINQ), 6, 439, 452 aggregation operations, 465 to collection objects, 455 accessing contained Subobjects, 455 nongeneric collections, 456 OfType(), filtering data, 457 CreateDataReader() method, 920–922 DataRowExtensions.Field() method, 924– 925 DataSet, 920–922 DataTable, 923–924 1475 www.it-ebooks.info ■ INDEX Language Integrated Query (cont.) extensions library, 922 internal representation, 466 QueryStringsWithAnonymousMethods(), 468 QueryStringsWithEnumerableAndLambd as() method, 467 QueryStringsWithOperators(), 466 VeryComplexQueryExpression, 469 limitations, 452 LinqRetValues application, 453 operators, 457 Basic Selection Syntax, 459 Count() extension method, 462 data types, 461 Reverse() extension method, 462 sorting expressions, 463 subsets of data, 460 queries, 925–926 removing duplicates, 464 Venn Diagramming tool, 463 Concat() extension method, 464 Except() extension method, 463 Intersect() method, 463 Union() method, 464 via immediate execution, 454 Late binding technique, 555, 574 invoking methods with no parameters, 576–577 with parameters, 577–578 System.Activator class, 574–576 LINQ to Objects, 439 anonymous types, 443 APIs, data types, 443 assemblies, 444–445 data access, 444 deferred execution, 450 extension methods, 442, 449 immediate execution, 452 implicitly typed local variables, 440, 448 lambda expressions, 441–442 LINQ query (see also Language Integrated Query (LINQ)) limitations, 452 LinqRetValues application, 453 via immediate execution, 454 object and collection initialization syntax, 441 programming constructs, 439 query expressions, 444 QueryOverStrings method, 447 ReflectOverQueryResults method, 447 LINQ to XML programming model, 967 in-memory XML document manipulation, 980 import Inventory.xml, 981 InsertNewElement() method, 982 LinqToXmlWinApp application, 980 LookUpColorsForMake() method, 982 static helper methods, 983 Inventory.xml file, 968 System.Xml.dll DOM model, 969 LinqToXmlFirstLook application, 967 W3C DOM, 968 System.Xml.Linq namespace axis methods, 974 class hierarchy, 973 extension methods, 973 members of, 972 types, 971 XName and XNamespace, 975 VB literal syntax, 969–971 XElement and XDocument, 975 arrays and containers, 978–979 ConstructingXmlDocs application, 976 Load() and Parse() methods, 979 XML APIs, 967 XmlDocument and XmlElement classes, 968 Logical trees Click event, 1318 differents, 1317–1318 LogicalTreeHelper clss, 1318 string member, 1318–1319 tree print out, 1319 XAML code, 1318 M Main() method application object, 74 static keyword, 74 variations on, 75 Managed heap, 473 Master pages, 1383 AdRotator control, 1403–1404 , 1399 breadcrumbs technique, 1403 BuildCar.aspx content page AspNetCarsSite web application, 1413 FinishButtonClick event, 1413 1476 www.it-ebooks.info ■ INDEX Label and Wizard control, 1412 ListBox control, 1413 content pages, 1397 default content page, 1404 inventory content page AutoLot database, 1407 GridView control, 1407 in-place editing, 1411 sorting and paging, 1410 SqlDataSource element, 1408 zero-code model, 1409 *.master file, 1397 shared UI, 1400 TreeView control SiteMapDataSource component, 1402 elements, 1401 Web.sitemap file, 1400 Member shadowing, 239 Member variables, 163 Metadata exchange (MEX), 1012, 1024 Method group conversion, 373 Method overloading, 130–132 Method overriding, 229 Microsoft ADO.NET data provider namespaces and assemblies, 805 ODBC types, 806 OLE DB data provider, 805 SQL Server provider, 805 System.Data.OracleClient.dll assembly, 806 third-party data providers, 806 Microsoft Message Queuing (MSMQ), 987 Microsoft Transaction Server (MTS), 987 Microsoft’s NET platform, assemblies, 9, 22 assembly manifest, 14 CIL code (see Common intermediate language (CIL)) external assemblies, 27 global assembly cache, 27 using ildasm.exe, 28–31 manifest, 10 metadata, 10 type metadata, 13 async and await, base class libraries, benefits, C# features, CLR, 4, 21 CLS, (see also Common language specification (CTS)) COM, CTS, (see also Common type system (CTS)) LINQ, managed vs unmanaged code, applications NET APIs, 36 start screen, 33 WinRT, 34 WPF, 35 namespace, 22 accessing programmatically, 26 Microsoft root namespace, 26 types, 24 NET 2.0, NET 3.5, NET 4.0, platform-independent nature of CLI, 31 VES, 31 programming languages DotNetLanguages.net, F#, multi-language world, type distinction, 22 Multiple exceptions, 271 compile-time errors, 273 finally blocks, 276 general catch statements, 274 inner exceptions, 275 rethrowing, 274 Multiple inheritance (MI), 216 Multithreaded application, 697 CLR thread pool, 729–731 concurrency problem MultiThreadedPrinting, 720 PrintNumbers() method, 721 NET delegates, 699 Add() method, 701 asynchronous method (see Asynchronous method) BinaryOp delegate, 699 Invoke() method, 700 Thread.Sleep() method, 700 vs process/AppDomain/Context, 697–698 concurrency problem, 698–699 thread synchronization, 727 synchronization C# lock keyword, 723–725 [synchronization] attribute, 727 System.Threading.Interlocked type, 726– 727 System.Threading.Monitor type, 725 1477 www.it-ebooks.info ■ INDEX Multithreaded application (cont.) System.Threading namespace (see System.Threading namespace) Timer callbacks, 727–729 MyTypeViewer fields and properties, 565 interfaces, 565 Main() method implementation, 566–568 method parameters and return values, 568– 569 methods, 564 odds and ends, 566 on generic types, 568 N Named arguments, 129 Nested panels, WPF control implementation MouseEnter and MouseLeave handlers, 1184–85 spell checking logic, 1185 menu system, 1179–82 StatusBar, 1183 Toolbar control, 1183 UI design, final aspect, 1183–84 XAML definition, 1179 NET assembly BAML, 1124–1125 mapping Application XAML markup, 1125– 1126 mapping Windows XAML markup, 1122–1124 XAML-to-Assembly process, 1126 NET attributes assembly-level attributes, 585 AssemblyInfo.cs file, 586 CLS-compliant assembly, 585 in C# ApplyingAttributes application, 579–581 shorthand notation, 581 constructor parameter, 581 consumers, 579 custom attributes named property syntax, 584 usage restriction, 584 VehicleDescriptionAttribute, 583–584 using early binding, 588–589 extendable application, 591 CommonSnappableTypes.dll, 592 CSharpSnapIn.dll, 593 MyExtendableApp.exe, 594 VbSnapIn.dll, 593 using late binding, 589–590 obsolete attribute, 582 predefined attributes, 578 NET data-access, 965–966 NET delegate type in C#, 360–362 callbacks, 359 System.MulticastDelegate and System.Delegate base classes, 362–364 NET exception handling, 254 building blocks, 255 System.Exception base class, 255–257 Windows API, 254 NET Framework 4.5 Software Development Kit (SDK) Developer Command Prompt, 40 misconception, 39 using Notepad++, 47 using SharpDevelop, 48 Visual C# Express, 51 Visual Studio, 52 NET platform application domain (see AppDomains) context boundaries (see Context boundaries) Process.GetProcessById() method, 629 Process.GetProcesses() method, 628–629 ProcessModuleCollection, 632–633 ProcessStartInfo class, 634–635 ProcessThread type, 629–631 Start() and Kill() method, 633–634 System.Diagnostics namespace, 626 System.Diagnostics.Process, 626–627 NET remoting, 988 Nongeneric collections issues of, 326 boxing and unboxing process, 327–328 value and reference types, 326 type safety, 330–332 System.Collections namespace, 323 ArrayList object, 324–325 key interfaces, 324 types, 323 System.Collections.Specialized Namespace, 325 Notepad++ autocompletion, 47 color coding, 47 syntax folding, 47 zooming, 47 1478 www.it-ebooks.info ■ INDEX Nullable data type, 157 O Object initializer syntax, 203 calling custom constructors with, 204, 205 inner types, 206, 207 Object Lifetime, 473 application roots categories, 477 clean and compacted heap, 479 garbage collection, 478 object graph, 478 basics of, 475 CIL newobj instruction, 475–477 garbage collector, 475 MakeACar() method, 475 references to null, 477 classes, objects and references, 473–474 disposable objects, 489 Close() method, 490 Dispose() method, 489 IDisposable interface, 489 is or as keywords, 490 using keyword, 491–492 finalizable and disposable blended technique, 493 formalized disposal pattern, 493–496 GC.SuppressFinalize() method, 493 MyResourceWrapper class, 493 Finalize() method AppDomains, 486 default implementation, 485 finalization process, 488 IDisposable interface, 486 overriding, 486–488 PInvoke, 486 unmanaged resources, 486 garbage collection NET 1.0–3.5, 480 NET 4.0, 481 generations, 479–480 LazyObjectInstantiation class types, 496 GetAllTracks() method, 497 Lazy variable, 498–499 System.GC type, 481 forcing garbage collection, 482–485 members, 481 Object (logical) resources application-level resources, 1278–1279 DynamicResource, 1277–1278 merged resource dictionary, 1280–1281 resource-only assemblies, 1281–1283 role, 1273–1274 StaticResource, 1277 window-wide resources, 1274–1276 Object serialization, 753, 780 attributes, 799–800 formatter (see Serialization formatter) ISerializable interface, 796 constructor, 797 CustomSerialization project, 797 GetObjectData() method, 796 MyStringData, 798 SerializationInfo class, 796 Main() method, 780 object graphs, 781–782, 795 public fields, private fields and public properties, 784 Serializable types, 783 Serialize() method, 792–794 System.Runtime.Serialization namespace, 794–795 UserPrefs object, 780 WCF service, 781 Object-oriented programming (OOP), 184 encapsulation, 184, 185 inheritance, 184–187 polymorphism, 184, 187–188 Operator overloading + operator, 404 += and _+ operators, 408 binary operators, 405–408 C# operators, 405 comparison operators, 410–411 equality operators, 409–410 MiniVan objects, 411 unary operators, 408–409 Optional arguments, 127 Output parameters, 123, 125 Overriding style, 1294 P Pages, 1096 Parallel LINQ Queries (PLINQ), 741 AsParallel() extension method, 743 Cancel() method, 743–744 ParallelEnumerable class, 742 1479 www.it-ebooks.info ■ INDEX Parallel LINQ Queries (cont.) PLINQDataProcessingWithCancellation, 742 Parallel programming, TPL, 731 accessing UI elements, 735–736 cancellation request, 736–738 data parallelism, 733–735 Parallel class, 732 Parallel.Invoke() method, 738–741 System.Threading.Tasks namespace, 731 Task class, 736 Parameter arrays, 126 Platform Invocation Services (PInvoke), 486 Polymorphic interface, 235–238 Polymorphism, 187–188, 213, 228 abstract classes, 233 member shadowing, 239–240 polymorphic interface, 235–238 virtual and override keywords, 229 virtual members overriding, Visual Studio 2010, 231 sealing, 232 Primary Interop Assemblies (PIAs), 613 Private assemblies App.Config file, 529–531 configuration, 527–529 identity of, 526 probing process, 526–527 Probing, 526 Process identifier (PID), 623 Publisher policy assemblies, 548 al.exe tool, 549 benefits, 549 disable option, 549 Q Queued Components (QC), 988 R Rectangular array, 136 Reference parameters, 125 Reflection services, 555, 560 dynamic load assemblies, 569–572 MyTypeViewer fields and properties, 565 interfaces, 565 Main() method implementation, 566–568 method parameters and return values, 568–569 methods, 564 odds and ends, 566 on generic types, 568 shared assemblies, 572–574 System.Reflection namespace, 561 using System.Object.GetType() method, 562 using System.Type.GetType() method, 563 System.Type class, 561–562 using typeof() method, 561–562 Resource system binary resources configuration, 1269 DockPanel, 1267 embedding application, 1271–1273 image loading program, 1270–1271 loose files, 1268 source properties, 1268 object (logical) resources application-level resources, 1278–1279 DynamicResource, 1277–1278 merged resource dictionary, 1280–1281 resource-only assemblies, 1281–1283 role, 1273–1274 StaticResource, 1277 window-wide resources, 1274–1276 Routing strategies, 1314 Runtime Callable Wrapper (RCW), 613 Runtime exception, 242 S Serialization formatter BinaryFormatter Deserialize() method, 787, 788–789 Main() method, 787 SaveAsBinaryFormat() method, 787 Serialize() method, 787–788 IFormatter, 785 IRemotingFormatter interface, 785 SoapFormatter type, 785, 789–790 type fidelity, 786–787 XmlSerializer type, 785, 790–792 Service contracts, 997 Service-oriented architecture (SOA) autonomous service, 991 boundaries, 991 definition, 991 interfaces, 991 service compatibility, 991 services communication, 991 1480 www.it-ebooks.info ■ INDEX TCP protocols, 992 Shadowing, 239 Shapes, 1225 adding shapes to canvas, 1227–30 Ellipse, 1225 FrameworkElement class, 1225 Line, 1225 MouseDown event, 1226 Path, 1225, 1232 Geometry-derived classes, 1233 modeling mini language, 1234–36 System.Windows.Media.Geometry type, 1232 Polygon, 1225 Polygons, 1231–32 Polyline, 1225 Polylines, 1231–32 properties, 1226 Rectangle, 1225 removing shapes from canvas, 1230–31 RenderingWithShapes application, 1225 UIElement class, 1225 Shared assemblies element, 547–548 CarLibrary 2.0.0.0, 544–547 configuration, 543 freezing the version, 544 GAC, 532–533 vs private assembly, 531 SharedCarLibClient, 542–543 strong names assembly-level attributes, 534 at command line, 535–537 to GAC, 539–541 GUID values, 534 using Visual Studio, 537–539 SharpDevelop benefits, 48 test project, 48 Silverlight, WPF, 1099 Single logical parameter, 126 Smart tag, 295 State management techniques application cache, 1442 *.aspx file modification, 1445–1447 data caching, 1443–1445 Insert() method, 1443 System.Web.Caching.Cache class, 1443 application/session distinction, 1438 AppState project, 1439 btnShowAppVariables button, 1440 CarLotInfo class, 1439 HttpApplicationState type, 1438 modifying application data, 1440–1442 ViewState property, 1439 web application shutdown, 1442 ASP.NET profile API, 1456 access programmatically, 1458–1460 ASPNETDB.mdf database, 1456–1457 grouping profile data and persistent custom objects, 1460–1462 web.config file, 1457–1458 cookies, 1451 access incoming data, 1453 persistent and temporary, 1452 System.Web.HttpCookie type, 1452 Global.asax file, 1435 Application_Error() event handler, 1436 event handlers, 1436 HttpApplication base class, 1437 issues, 1429–1431 session state, 1448 GUI, 1449 HttpSessionState type, 1450 Session_Start() and Session_End() event, 1448 UserShoppingCart class, 1448 element, 1454 ASP.NET session state server, 1454 in a dedicated database, 1455–1456 view state, 1432 adding custom data, 1434 demonstration, 1432–1434 Static keyword, 177 static classes, 183–184 static constructors, 181–183 static data, 178–179 static method, 179–181 utility classes, 177 Structure types See C# programming constructs, structure type Structured exception handling, 253 application-level exceptions (System.ApplicationException), 266– 271 bugs, 253 Car and Radio class, 257 catching exceptions, 260 configuring state of, 261 Data property, 264–265 HelpLink property, 263 StackTrace property, 262 1481 www.it-ebooks.info ■ INDEX Structured exception handling, configuring state of (cont.) TargetSite property, 261, 262 exceptions, 253 multiple exceptions, 271 compile-time errors, 273 finally blocks, 276 general catch statements, 274 inner exceptions, 275 rethrowing, 274 NET (see NET exception handling) system-level exceptions (System.SystemException), 266 throwing an exceptions, 259 throws, identifying, 277 unhandled exceptions, 277 user errors, 253 Styles animation sequence, 1297–1298 class, 1292 definition, 1293 multiple triggers, 1297 overriding style, 1294 programmatics, 1298–1299 subclass exists, 1295 TargetType, 1294–1295 triggers, 1296–1297 unnamed styles, 1295 Synchronously method, 360 System.Collections.Generic namespace, 338 classes, 339 collection initialization syntax, 340–341 key interfaces, 338 List class, 341–342 Queue class, 343–345 SortedSet class, 345–346 Stack class, 342–343 System.Collections.ObjectModel namespace members of, 346 ObservableCollection class, 347–349 System.Collections.Specialized Namespace, 325 System.Data namespace, 807 IDataReader and IDataRecord interfaces, 811 IDbCommand interface, 809 IDbConnection interface, 809 IDbDataAdapter and IDataAdapter interfaces, 811 IDbDataParameter and IDataParameter interfaces, 810 IDbTransaction interface, 809 types, 808 System.IO Namespace, 753 abstract stream class, 768 FileStream class, 770–771 members, 769 BinaryWriters and BinaryReaders, 776–778 Directory (Info) type, 754 CreateSubdirectory() method, 758–760 DirectoryApp application, 757 dot (.) notation, 756 GetFiles() method, 758 members, 756 Directory type, 754, 760 DriveInfo class type, 760–762 File (Info) type, 754 File type, 754 methods, 767 static members, 766 FileInfo class, 762 AppendText() method, 766 Create() method, 763 CreateText() method, 766 members, 762 Open() method, 764–765 OpenRead() method, 765 OpenText() method, 766 OpenWrite() method, 765 FileSystemInfo class, 755–756 FileSystemWatcher type, 778–780 members of, 753 StreamWriters and StreamReaders CreateText() method, 774 FileStream class, 771 TextReader, 771, 773 TextWriter, 771, 772 StringWriters and StringReaders, 774–776 types, 753 System-level exceptions (System.SystemException), 266 System.Object class overriding system.Object.Equals(), 247, 248 System.Object.GetHashCode(), 248 static members of, 250 System.Object.Equals() method, 247, 248 System.Object.GetHashCode() method, 248 System.Threading namespace AutoResetEvent class, 718–719 CLR, 709 creation process, 714 foreground and background threads, 719–720 1482 www.it-ebooks.info ■ INDEX ParameterizedThreadStart delegates, 717– 718 Thread class, 711 instance-level members, 711 Name property, 713 Priority property, 713 static members, 711 ThreadStats, 712–713 ThreadStart delegates, 715–717 types of, 710  T, U Task Parallel Library (TPL), 731 accessing UI elements, 735–736 cancellation request, 736–738 data parallelism, 733–735 Parallel class, 732 Parallel.Invoke() method, 738–741 System.Threading.Tasks namespace, 731 Task class, 736 TabControl, WPF APIs initial layout, 1193 Ink API tab ComboBox control, 1205–6 handling events, 1201 InkCanvas control, 1202–4 layout manager, 1195 RadioButton control, 1199 saving loading and clearing, 1207 toolbar designing, 1196–99 Tabitems addition, 1193 Toolbox window, 1194–95 Themes, 1383 App_Theme folder, 1423 Page_PreInit() event, 1427–1428 page-by-page level, 1426 site-wide themes, 1426 *.skin files, 1423–1425 SkinID property, 1426 style sheets, 1422 TimerApp, 727–729 TimerCallback delegate, 728 Trigger framework ButtonTemplate, 1326 Click event handler, 1326 ContentPresenter, 1331–1332 markup extension, 1329–1331 styles, 1332–1333 templates vs resources, 1326–1328 Visual cues, 1329 VSM, 1325 Tunneling events, 1314, 1315–1317 Type metadata, 555 Car type, 557–558 documentation assembly, definition, 559 referenced assemblies, 559 string literals, 560 EngineState enumeration, 556–557 ildasm.exe, 556 TypeRef, 559 V Validation controls, 1415 client-side JavaScript code, 1417 CompareValidator, 1418–1419 properties, 1415 RangeValidator, 1418 RegularExpressionValidator, 1418 RequiredFieldValidator, 1417 ValidationGroups, 1421–1422 ValidationSummary widget, 1419–1421 ValidatorCtrls, 1416 Value types, 157 Virtual directory, 1339 Virtual Execution System (VES), 31 Virtual members overriding, Visual Studio 2010, 231 sealing, 232 Visual C# Express SQL Server Express, 52 unique features, 52 Visual Basic Express, 52 Visual C++ Express, 52 Visual Web Developer Express, 52 Visual State Manager (VSM), 1325 Visual Studio, 52 Class View Utility, 57 code expansions, 62 integrated NET Framework 4.0 documentation, 67 New Project Dialog Box, 54 Object Browser Utility, 58 refactoring code, 59 Solution Explorer Utility, 54 Project Properties window, 56 referencing external assemblies, 55 unique features, 53 1483 www.it-ebooks.info ■ INDEX Visual Studio (cont.) Visual Class Designer, 63 WPF, 1139 autogenerated files, 1147 Document Outline Window, 1146 in XAML editor, 1146 project templates, 1139–1141 properties window, 1143–1145 Toolbox and XAML Designer/Editor, 1141 Visual Studio 2010 implementing interfaces using, 295 overriding virtual members, 231 Visual Studio HTML designer tools, 1342–1344 Visual Studio WCF project template, 993 App.config file, 994 benefits, 994 RSS library, 995 web-based WCF, 995 Visual trees differents, 1317–1318 tree output, 1320 VisualTreeHelper class, 1319–1320 W WCF data contracts, 1039 service implementation, 1042–1043 *.svc file, 1043 testing, 1044 web-centric WCF service, 1040–1042 configuration project, 1040 methods, 1041 uniquely named, 1042 Web.config file, 1043–1044 Web applications and servers components, 1338 development, 1339 virtual directories, 1339 Web page advantages, 1352 aspx file, 1352 AutoEventWireup attribute, 1379 AutoLotDAL.dll, 1354 code files AutoLotDAL.dll Assembly, 1364 code-behind model, 1361 CodeFile attribute, 1363 code separation, 1363 debugging and tracing, 1365–1366 Empty Web Site template, 1362 Load event, 1364 updation, 1365 control declarations, 1360–1361 data access logics, 1355–1358 data-binding model, 1356 directives, 1358–1359 error event, 1380–1381 GridView control, 1357 life cycle, 1378 NET class type, 1361 script block, 1359 single-file page model, 1352 test page, 1358 UI designing, 1354–1355 Unload event, 1378–1379 Web server action attribute, 1348 tag, 1348 Postbacks, 1349 submit button, 1348–1349 Web Service Description Language (WSDL), 989 Web site App_Code folder, 1370–1371 directory structure, 1369 referencing assemblies, 1369–1370 vs web applications, 1367–1368 Windows Communication Foundation (WCF), 985, 990 addresses, 1001–1002 assemblies, 992 bindings, 999 characteristics, 999 HTTP-based, 999–1000 MSMQ-based, 1001 TCP-based, 1000–1001 client applications, 996 client-side proxy configuration options, 1038 configuration settings, 1020 BasicHttpBinding class, 1022–1024 client proxy and binding selection, 1025– 1026 default endpoints, 1020–1021 exposing, multiple bindings, 1021–1022 MEX service behavior, 1024–1025 contracts, 997 data contracts, 1039 service implementation, 1042–1043 *.svc file, 1043 testing, 1044 web-centric WCF service, 1040–1042 Web.config file, 1043–1044 1484 www.it-ebooks.info ■ INDEX distributed computing APIs COM+/Enterprise Services, 987 DCOM, 986–987 definition, 985 issues, 986 MSMQ, 1001 NET remoting, 988 tasks, 986 Web Service Standards, 989 XML Web Services, 988–989 features, 990–991 hosting application, GUI, 1030 ABCs specification in code, 1031–1033 enabling MEX, 1033 MathWindowsServiceHost, 1031 Windows Service installation, 1035–1036 Windows Service Installer, 1033–1035 hosting services, 1006 App.config file, 1007 base addresses, 1008–1009 metadata exchange, 1012–1015 ServiceHost type, 1007–1008, 1009–1011 element, 1011– 1012 MagicEightBallServiceLib, 1002 MathClient application, 1036 namespaces, 993 [OperationContract] attribute, 1005 proxy code generation svcutil.exe, 1015–1016 Visual Studio, 1016–1018 Service assembly, 996 [ServiceContract] attribute, 1004 Service host, 996 Service Library Project template, 1027 MathServiceLibrary, 1027 SvcConfigEditor.exe, 1028–1030 with WcfTestClient.exe, 1044 service types, 1005–1006 SOA (see Service-oriented architecture (SOA)) TCP-based binding configuration, 1018–1020 Visual Studio Service Library project template, 993 App.config file, 994 benefits, 994 RSS library, 994 web-based WCF, 995 Windows Forms GUIs See Database designer tools; Data binding entities; DataTables Windows Presentation Foundation (WPF), 35, 1091, 1267, 1301 animation services APIs, 1284 C# code, 1286–1287 class types, 1284–1285 pace controls, 1288 reversing and looping, 1288–1289 Timeline Base Class, 1285 To, From and By properties, 1285 Application class, 1101 construction, 1102 properties, 1101 Windows collection, 1102–1103 assemblies, 1099 using code-behind files for MainWindow class, 1136–1137 for MyApp class, 1137–1138 with msbuild.exe, 1138–1139 custom dependency properties Content properties, 1307 CurrentNumber, 1308, 1311 data validation routine, 1311–1312 expand snippet, 1311–1312 Label control, 1307 propdp code, 1310 properties change, 1312–1313 user control menu option, 1306 XAML definition, 1308 default template ControlTemplate, 1324–1325 ControlTemplate class, 1321 differents, 1317–1318 member variable, 1323–1324 StackPanel and DockPanel, 1322 UI updation, 1323 dependency properties CLR properties, 1302 CLR wrapper, 1305–1306 ControlContent, 1301 definition, 1301 DependencyProperty.Register(), 1304 existing properties, 1303–1305 FrameworkElement, 1301 FrameworkPropertyMetadata, 1304 GetValue() and SetValue() methods, 1304, 1305 SetBinding() method, 1302 steps, 1302 UserControl classes, 1303 desired functionalities NET 3.0 solutions, 1092 pre-WPF solutions, 1092 1485 www.it-ebooks.info ■ INDEX Windows Presentation Foundation (cont.) desktop applications, 1094–1096 logical resource, 1267 logical trees Click event, 1318 differents, 1317–1318 LogicalTreeHelper classes, 1318 string member, 1318–1319 tree print out, 1319 XAML code, 1318 namespaces, 1100 navigation-based applications, 1096 optimized rendering model, 1093 resourcen system binary resources, 1267–1273 object (logical) resources, 1273–1283 routed events bubbling events, 1314–1315 controls, 1313 Click event, 1313 complex content, 1313 direct event, 1314 halting bubbling, 1315 tunneling events, 1314, 1315–1317 Silverlight relationship, 1099 simplifying UI programming, 1094 styles animation sequence, 1297–1298 class, 1292 definition, 1293 multiple triggers, 1297 overriding style, 1294 programmatics, 1298–1299 subclass exists, 1295 TargetType, 1294–1295 triggers, 1296–1297 unnamed styles, 1295 unifying APIs, 1092–1093, 1092–1093 using Visual Studio, 1139 autogenerated files, 1147 Document Outline Window, 1146 in XAML editor, 1146 properties window, 1143–1145 Toolbox and XAML Designer/Editor, 1141 WPF project templates, 1139–1141 Visual trees differents, 1317–1318 tree output, 1320 VisualTreeHelper class, 1319–1320 Window class inheritance chain and implemented interfaces, 1103 System.Windows.Controls.ContentContr ol type, 1103–1105 System.Windows.Controls.Control type, 1105 System.Windows.DependencyObject type, 1107 System.Windows.FrameworkElement type, 1105 System.Windows.Media.Visual type, 1107 System.Windows.Threading.DispatcherO bject type, 1107 System.Windows.UIElement type, 1106 with XAML, 1117 Application object, 1119–1120 attached properties, 1133–1134 attributes, 1132 class and member variable visibility, 1131 code file approach, 1117 elements, 1131 Kaxaml, 1127–1128 markup extensions, 1134–1136 using msbuild.exe, 1120–1122 NET assembly (see NET assembly) nonabstract NET types, 1117 property-element syntax, 1133 type converters, 1132 Window object, 1118–1119 XML namespaces and keywords, 1128– 1131 without XAML, 1107 application level data, interacting with, 1112–1113 AppStartUp() method, 1109 Close() method, 1153 keyboard events interception, 1115–1116 Main() method, 1109 mouse events interception, 1114–1115 strongly typed window, 1109–1110 user interface creation, 1110–1112 XBAP applications, 1097–1098 Windows Process, 623 NET platform application domain (see AppDomains) Process.GetProcessById() method, 629 Process.GetProcesses() method, 628–629 ProcessModuleCollection, 632–633 ProcessStartInfo class, 634–635 ProcessThread type, 629–631 Start() and Kill() method, 633–634 1486 www.it-ebooks.info ■ INDEX System.Diagnostics namespace, 626 System.Diagnostics.Process, 626–627 PID, 623 threads, 624–625 Windows Task Manager utility, 624 Windows Runtime (WinRT), 34 Windows Workflow Foundation, 1047 activities, 1057 collection and error handling, 1060–1061 control flow, 1057–1058 flowchart, 1058 messaging, 1058–1059 Runtime and Primitives, 1059–1060 state machines, 1059 transaction, 1060 business processes, 1047–1048 FirstWorkflowExampleApp, 1049 flowchart workflow, 1061 connecting activities, 1062–1063 FlowDecision activity, 1065–1066 ForEach activity, 1067–1070 InvokeMethod activity, 1063–1064 reflection, 1071–1072 System.Collections.Generic namespace, 1070–1071 TerminateWorkflow activity, 1066–1067 true condition, 1067 workflow-wide variables, 1064–1065 role of, 1048 sequence workflow, 1073 arguments, 1075–1076 Assign activity, 1077–1078 custom code activity, 1081–1084 If and Switch activities, 1078–1081 importing assemblies and namespaces, 1074–1075 Initial project, 1073–1074 variables, 1076–1077 WF 4.0 runtime, 1051 Dictionary object, 1056 WorkflowApplication, 1055–1056 WorkflowInvoker, 1052–1055 workflow library output arguments, 1085 WorkflowLibraryClient, 1084 XAML dialect, 1048 WorkflowInvoker, 1052 defining arguments, 1053–1055 Invoke() method, 1052 passing arguments, 1052 synchronous blocking manner, 1052  X, Y, Z Xcopy deployment, 526 XML Web Services agnostic manner, 988 drawbacks, 989 interoperability, 989 1487 www.it-ebooks.info ... of the front matter material after the index Please use the Bookmarks and Contents at a Glance links to access them www.it-ebooks.info Pro C# 5.0 and the NET 4.5 Framework Sixth Edition  Andrew... www.it-ebooks.info Pro C# and the NET 4.5 Framework, Sixth Edition Copyright © 2012 by Andrew Troelsen This work is subject to copyright All rights are reserved by the Publisher, whether the whole or part of the. .. Configuring the State of an Exception 261 The TargetSite Property 261 The StackTrace Property 262 The HelpLink Property 263 The Data Property

Ngày đăng: 06/03/2019, 13:35

Từ khóa liên quan

Mục lục

  • Cover

    • Contents at a Glance

    • Contents

    • About the Author

    • About the Technical Reviewer

    • Acknowledgments

    • Introduction

      • Part I: Introducing C# and the .NET Platform

      • Part II: Core C# Programming

      • Part III: Object-Oriented Programming with C#

      • Part IV: Advanced C# Programming

      • Part V: Programming with .NET Assemblies

      • Part VI: Introducing the .NET Base Class Libraries

      • Part VII: Windows Presentation Foundation

      • Part VIII: ASP.NET Web Forms

  • The Philosophy of .NET

    • An Initial Look at the .NET Platform

      • Some Key Benefits of the .NET Platform

    • Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS)

      • The Role of the Base Class Libraries

      • What C# Brings to the Table

      • Managed vs. Unmanaged Code

    • Additional .NET-Aware Programming Languages

      • Life in a Multilanguage World

    • An Overview of .NET Assemblies

      • The Role of the Common Intermediate Language

      • The Role of .NET Type Metadata

      • The Role of the Assembly Manifest

    • Understanding the Common Type System

      • CTS Class Types

      • CTS Interface Types

      • CTS Structure Types

      • CTS Enumeration Types

      • CTS Delegate Types

      • CTS Type Members

      • Intrinsic CTS Data Types

    • Understanding the Common Language Specification

      • Ensuring CLS Compliance

    • Understanding the Common Language Runtime

    • The Assembly/Namespace/Type Distinction

      • The Role of the Microsoft Root Namespace

      • Accessing a Namespace Programmatically

      • Referencing External Assemblies

    • Exploring an Assembly Using ildasm.exe

      • Viewing CIL Code

      • Viewing Type Metadata

      • Viewing Assembly Metadata (a.k.a. the Manifest)

    • The Platform-Independent Nature of .NET

    • A Brief Word Regarding Windows 8 Applications

      • Building Applications

      • The Role of .NET Under Windows 8

    • Summary

  • Building C# Applications

    • The Role of the .NET Framework 4.5 SDK

      • The Developer Command Prompt

    • Building C# Applications Using csc.exe

      • Specifying Input and Output Targets

      • Referencing External Assemblies

      • Referencing Multiple External Assemblies

      • Compiling Multiple Source Files

      • Working with C# Response Files

    • Building .NET Applications Using Notepad++

    • Building .NET Applications Using SharpDevelop

      • Building a Simple Test Project

    • Building .NET Applications Using Visual C# Express

      • Some Unique Features of Visual C# Express

    • Building .NET Applications Using Visual Studio

      • Some Unique Features of Visual Studio

      • Targeting the .NET Framework Using the New Project Dialog Box

      • Using the Solution Explorer Utility

      • The Class View Utility

      • The Object Browser Utility

      • Integrated Support for Code Refactoring

      • Code Snippets and Surround with Technology

      • The Visual Class Designer

      • The Integrated .NET Framework 4.5 SDK Documentation System

    • Summary

  • Core C# Programming Constructs, Part I

    • The Anatomy of a Simple C# Program

      • Variations on the Main() Method

      • Specifying an Application Error Code

      • Processing Command-Line Arguments

      • Specifying Command-Line Arguments with Visual Studio

    • An Interesting Aside: Some Additional Members of the System.Environment Class

    • The System.Console Class

      • Basic Input and Output with the Console Class

      • Formatting Console Output

      • Formatting Numerical Data

      • Formatting Numerical Data Beyond Console Applications

    • System Data Types and Corresponding C# Keywords

      • Variable Declaration and Initialization

      • Intrinsic Data Types and the new Operator

      • The Data Type Class Hierarchy

      • Members of Numerical Data Types

      • Members of System.Boolean

      • Members of System.Char

      • Parsing Values from String Data

      • System.DateTime and System.TimeSpan

      • The System.Numerics.dll Assembly

    • Working with String Data

      • Basic String Manipulation

      • String Concatenation

      • Escape Characters

      • Defining Verbatim Strings

      • Strings and Equality

      • Strings Are Immutable

      • The System.Text.StringBuilder Type

    • Narrowing and Widening Data Type Conversions

      • The checked Keyword

      • Setting Project-Wide Overflow Checking

      • The unchecked Keyword

    • Understanding Implicitly Typed Local Variables

      • Restrictions on Implicitly Typed Variables

      • Implicit Typed Data Is Strongly Typed Data

      • Usefulness of Implicitly Typed Local Variables

    • C# Iteration Constructs

      • The for Loop

      • The foreach Loop

      • The while and do/while Looping Constructs

    • Decision Constructs and the Relational/Equality Operators

      • The if/else Statement

      • Equality and Relational Operators

      • Conditional Operators

      • The switch Statement

    • Summary

  • Core C# Programming Constructs, Part II

    • Methods and Parameter Modifiers

      • The Default by Value Parameter-Passing Behavior

      • The out Modifier

      • The ref Modifier

      • The params Modifier

      • Defining Optional Parameters

      • Invoking Methods Using Named Parameters

      • Understanding Method Overloading

    • Understanding C# Arrays

      • C# Array Initialization Syntax

      • Implicitly Typed Local Arrays

      • Defining an Array of Objects

      • Working with Multidimensional Arrays

      • Arrays As Arguments or Return Values

      • The System.Array Base Class

    • Understanding the enum Type

      • Controlling the Underlying Storage for an enum

      • Declaring enum Variables

      • The System.Enum Type

      • Dynamically Discovering an enum’s Name/Value Pairs

    • Understanding the Structure Type

      • Creating Structure Variables

    • Understanding Value Types and Reference Types

      • Value Types, References Types, and the Assignment Operator

      • Value Types Containing Reference Types

      • Passing Reference Types by Value

      • Passing Reference Types by Reference

      • Final Details Regarding Value Types and Reference Types

    • Understanding C# Nullable Types

      • Working with Nullable Types

      • The ?? Operator

    • Summary

  • Understanding Encapsulation

    • Introducing the C# Class Type

      • Allocating Objects with the new Keyword

    • Understanding Constructors

      • The Role of the Default Constructor

      • Defining Custom Constructors

      • The Default Constructor Revisited

    • The Role of the this Keyword

      • Chaining Constructor Calls Using this

      • Observing Constructor Flow

      • Revisiting Optional Arguments

    • Understanding the static Keyword

      • Defining Static Field Data

      • Defining Static Methods

      • Defining Static Constructors

      • Defining Static Classes

    • Defining the Pillars of OOP

      • The Role of Encapsulation

      • The Role of Inheritance

      • The Role of Polymorphism

    • C# Access Modifiers

      • The Default Access Modifiers

      • Access Modifiers and Nested Types

    • The First Pillar: C#’s Encapsulation Services

      • Encapsulation Using Traditional Accessors and Mutators

      • Encapsulation Using .NET Properties

      • Using Properties Within a Class Definition

      • Read-Only and Write-Only Properties

      • Revisiting the static Keyword: Defining Static Properties

    • Understanding Automatic Properties

      • Interacting with Automatic Properties

      • Regarding Automatic Properties and Default Values

    • Understanding Object Initialization Syntax

      • Calling Custom Constructors with Initialization Syntax

      • Initializing Inner Types

    • Working with Constant Field Data

      • Understanding Read-Only Fields

      • Static Read-Only Fields

    • Understanding Partial Types

    • Summary

  • Understanding Inheritance and Polymorphism

    • The Basic Mechanics of Inheritance

      • Specifying the Parent Class of an Existing Class

      • Regarding Multiple Base Classes

      • The sealed Keyword

    • Revising Visual Studio Class Diagrams

    • The Second Pillar of OOP: The Details of Inheritance

      • Controlling Base Class Creation with the base Keyword

      • Keeping Family Secrets: The protected Keyword

      • Adding a Sealed Class

    • Programming for Containment/Delegation

      • Understanding Nested Type Definitions

    • The Third Pillar of OOP: C#’s Polymorphic Support

      • The virtual and override Keywords

      • Overriding Virtual Members Using the Visual Studio IDE

      • Sealing Virtual Members

      • Understanding Abstract Classes

      • Understanding the Polymorphic Interface

      • Understanding Member Shadowing

    • Understanding Base Class/Derived Class Casting Rules

      • The C# as Keyword

      • The C# is Keyword

    • The Master Parent Class: System.Object

      • Overriding System.Object.ToString()

      • Overriding System.Object.Equals()

      • Overriding System.Object.GetHashCode()

      • Testing Your Modified Person Class

      • The Static Members of System.Object

    • Summary

  • Understanding Structured Exception Handling

    • Ode to Errors, Bugs, and Exceptions

    • The Role of .NET Exception Handling

      • The Building Blocks of .NET Exception Handling

      • The System.Exception Base Class

    • The Simplest Possible Example

      • Throwing a General Exception

      • Catching Exceptions

    • Configuring the State of an Exception

      • The TargetSite Property

      • The StackTrace Property

      • The HelpLink Property

      • The Data Property

    • System-Level Exceptions (System.SystemException)

    • Application-Level Exceptions (System.ApplicationException)

      • Building Custom Exceptions, Take One

      • Building Custom Exceptions, Take Two

      • Building Custom Exceptions, Take Three

    • Processing Multiple Exceptions

      • General catch Statements

      • Rethrowing Exceptions

      • Inner Exceptions

      • The finally Block

    • Who Is Throwing What?

    • The Result of Unhandled Exceptions

    • Debugging Unhandled Exceptions Using Visual Studio

    • Summary

  • Working with Interfaces

    • Understanding Interface Types

      • Interface Types vs. Abstract Base Classes

    • Defining Custom Interfaces

    • Implementing an Interface

    • Invoking Interface Members at the Object Level

      • Obtaining Interface References: The as Keyword

      • Obtaining Interface References: The is Keyword

    • Interfaces As Parameters

    • Interfaces As Return Values

    • Arrays of Interface Types

    • Implementing Interfaces Using Visual Studio

    • Explicit Interface Implementation

    • Designing Interface Hierarchies

      • Multiple Inheritance with Interface Types

    • The IEnumerable and IEnumerator Interfaces

      • Building Iterator Methods with the yield Keyword

      • Building a Named Iterator

    • The ICloneable Interface

      • A More Elaborate Cloning Example

    • The IComparable Interface

      • Specifying Multiple Sort Orders with IComparer

      • Custom Properties and Custom Sort Types

    • Summary

  • Collections and Generics

    • The Motivation for Collection Classes

      • The System.Collections Namespace

      • A Survey of System.Collections.Specialized Namespace

    • The Problems of Nongeneric Collections

      • The Issue of Performance

      • The Issue of Type Safety

      • A First Look at Generic Collections

    • The Role of Generic Type Parameters

      • Specifying Type Parameters for Generic Classes/Structures

      • Specifying Type Parameters for Generic Members

      • Specifying Type Parameters for Generic Interfaces

    • The System.Collections.Generic Namespace

      • Understanding Collection Initialization Syntax

      • Working with the List<T> Class

      • Working with the Stack<T> Class

      • Working with the Queue<T> Class

      • Working with the SortedSet<T> Class

    • The System.Collections.ObjectModel Namespace

      • Working with ObservableCollection<T>

    • Creating Custom Generic Methods

      • Inference of Type Parameters

    • Creating Custom Generic Structures and Classes

      • The default Keyword in Generic Code

    • Constraining Type Parameters

      • Examples Using the where Keyword

      • The Lack of Operator Constraints

    • Summary

  • Delegates, Events, and Lambda Expressions

    • Understanding the .NET Delegate Type

      • Defining a Delegate Type in C#

      • The System.MulticastDelegate and System.Delegate Base Classes

    • The Simplest Possible Delegate Example

      • Investigating a Delegate Object

    • Sending Object State Notifications Using Delegates

      • Enabling Multicasting

      • Removing Targets from a Delegate’s Invocation List

      • Method Group Conversion Syntax

    • Understanding Generic Delegates

      • The Generic Action<> and Func<> Delegates

    • Understanding C# Events

      • The C# event Keyword

      • Events Under the Hood

      • Listening to Incoming Events

      • Simplifying Event Registration Using Visual Studio

      • Creating Custom Event Arguments

      • The Generic EventHandler<T> Delegate

    • Understanding C# Anonymous Methods

      • Accessing Local Variables

    • Understanding Lambda Expressions

      • Dissecting a Lambda Expression

      • Processing Arguments Within Multiple Statements

      • Lambda Expressions with Multiple (or Zero) Parameters

      • Retrofitting the CarEvents Example Using Lambda Expressions

    • Summary

  • Advanced C# Language Features

    • Understanding Indexer Methods

      • Indexing Data Using String Values

      • Overloading Indexer Methods

      • Indexers with Multiple Dimensions

      • Indexer Definitions on Interface Types

    • Understanding Operator Overloading

      • Overloading Binary Operators

      • And What of the += and –+ Operators?

      • Overloading Unary Operators

      • Overloading Equality Operators

      • Overloading Comparison Operators

      • Final Thoughts Regarding Operator Overloading

    • Understanding Custom Type Conversions

      • Recall: Numerical Conversions

      • Recall: Conversions Among Related Class Types

      • Creating Custom Conversion Routines

      • Additional Explicit Conversions for the Square Type

      • Defining Implicit Conversion Routines

    • Understanding Extension Methods

      • Defining Extension Methods

      • Invoking Extension Methods

      • Importing Extension Methods

      • The IntelliSense of Extension Methods

      • Extending Types Implementing Specific Interfaces

    • Understanding Anonymous Types

      • Defining an Anonymous Type

      • The Internal Representation of Anonymous Types

      • The Implementation of ToString() and GetHashCode()

      • The Semantics of Equality for Anonymous Types

      • Anonymous Types Containing Anonymous Types

    • Working with Pointer Types

      • The unsafe Keyword

      • Working with the * and & Operators

      • An Unsafe (and Safe) Swap Function

      • Field Access via Pointers (the -> Operator)

      • The stackalloc Keyword

      • Pinning a Type via the fixed Keyword

      • The sizeof Keyword

    • Summary

  • LINQ to Objects

    • LINQ-Specific Programming Constructs

      • Implicit Typing of Local Variables

      • Object and Collection Initialization Syntax

      • Lambda Expressions

      • Extension Methods

      • Anonymous Types

    • Understanding the Role of LINQ

      • LINQ Expressions Are Strongly Typed

      • The Core LINQ Assemblies

    • Applying LINQ Queries to Primitive Arrays

      • Once Again, Without LINQ

      • Reflecting over a LINQ Result Set

      • LINQ and Implicitly Typed Local Variables

      • LINQ and Extension Methods

      • The Role of Deferred Execution

      • The Role of Immediate Execution

    • Returning the Result of a LINQ Query

      • Returning LINQ Results via Immediate Execution

    • Applying LINQ Queries to Collection Objects

      • Accessing Contained Subobjects

      • Applying LINQ Queries to Nongeneric Collections

      • Filtering Data Using OfType<T>()

    • Investigating the C# LINQ Query Operators

      • Basic Selection Syntax

      • Obtaining Subsets of Data

      • Projecting New Data Types

      • Obtaining Counts Using Enumerable

      • Reversing Result Sets

      • Sorting Expressions

      • LINQ As a Better Venn Diagramming Tool

      • Removing Duplicates

      • LINQ Aggregation Operations

    • The Internal Representation of LINQ Query Statements

      • Building Query Expressions with Query Operators (Revisited)

      • Building Query Expressions Using the Enumerable Type and Lambda Expressions

      • Building Query Expressions Using the Enumerable Type and Anonymous Methods

      • Building Query Expressions Using the Enumerable Type and Raw Delegates

    • Summary

  • Understanding Object Lifetime

    • Classes, Objects, and References

    • The Basics of Object Lifetime

      • The CIL of new

      • Setting Object References to null

    • The Role of Application Roots

    • Understanding Object Generations

    • Concurrent Garbage Collection Under .NET 1.0–3.5

    • Background Garbage Collection Under .NET 4.0 and Greater

    • The System.GC Type

      • Forcing a Garbage Collection

    • Building Finalizable Objects

      • Overriding System.Object.Finalize()

      • Detailing the Finalization Process

    • Building Disposable Objects

      • Reusing the C# using Keyword

    • Building Finalizable and Disposable Types

      • A Formalized Disposal Pattern

    • Understanding Lazy Object Instantiation

      • Customizing the Creation of the Lazy Data

    • Summary

  • Building and Configuring Class Libraries

    • Defining Custom Namespaces

      • Resolving Name Clashes with Fully Qualified Names

      • Resolving Name Clashes with Aliases

      • Creating Nested Namespaces

      • The Default Namespace of Visual Studio

    • The Role of .NET Assemblies

      • Assemblies Promote Code Reuse

      • Assemblies Establish a Type Boundary

      • Assemblies Are Versionable Units

      • Assemblies Are Self-Describing

      • Assemblies Are Configurable

    • Understanding the Format of a .NET Assembly

      • The Windows File Header

      • The CLR File Header

      • CIL Code, Type Metadata, and the Assembly Manifest

      • Optional Assembly Resources

    • Building and Consuming Custom Class Library

      • Exploring the Manifest

      • Exploring the CIL

      • Exploring the Type Metadata

      • Building a C# Client Application

      • Building a Visual Basic Client Application

      • Cross-Language Inheritance in Action

    • Understanding Private Assemblies

      • The Identity of a Private Assembly

      • Understanding the Probing Process

      • Configuring Private Assemblies

      • The Role of the App.Config File

    • Understanding Shared Assemblies

      • The Global Assembly Cache

      • Understanding Strong Names

      • Generating Strong Names at the Command Line

      • Generating Strong Names Using Visual Studio

      • Installing Strongly Named Assemblies to the GAC

    • Consuming a Shared Assembly

      • Exploring the Manifest of SharedCarLibClient

    • Configuring Shared Assemblies

      • Freezing the Current Shared Assembly

      • Building a Shared Assembly Version 2.0.0.0

      • Dynamically Redirecting to Specific Versions of a Shared Assembly

    • Understanding Publisher Policy Assemblies

      • Disabling Publisher Policy

    • Understanding the <codeBase> Element

    • The System.Configuration Namespace

    • The Configuration File Schema Documentation

    • Summary

  • Type Reflection, Late Binding, and Attribute-Based Programming

    • The Necessity of Type Metadata

      • Viewing (Partial) Metadata for the EngineState Enumeration

      • Viewing (Partial) Metadata for the Car Type

      • Examining a TypeRef

      • Documenting the Defining Assembly

      • Documenting Referenced Assemblies

      • Documenting String Literals

    • Understanding Reflection

      • The System.Type Class

      • Obtaining a Type Reference Using System.Object.GetType()

      • Obtaining a Type Reference Using typeof()

      • Obtaining a Type Reference Using System.Type.GetType()

    • Building a Custom Metadata Viewer

      • Reflecting on Methods

      • Reflecting on Fields and Properties

      • Reflecting on Implemented Interfaces

      • Displaying Various Odds and Ends

      • Implementing Main()

      • Reflecting on Generic Types

      • Reflecting on Method Parameters and Return Values

    • Dynamically Loading Assemblies

    • Reflecting on Shared Assemblies

    • Understanding Late Binding

      • The System.Activator Class

      • Invoking Methods with No Parameters

      • Invoking Methods with Parameters

    • Understanding the Role of .NET Attributes

      • Attribute Consumers

      • Applying Attributes in C#

      • C# Attribute Shorthand Notation

      • Specifying Constructor Parameters for Attributes

      • The Obsolete Attribute in Action

    • Building Custom Attributes

      • Applying Custom Attributes

      • Named Property Syntax

      • Restricting Attribute Usage

    • Assembly-Level Attributes

      • The Visual Studio AssemblyInfo.cs File

    • Reflecting on Attributes Using Early Binding

    • Reflecting on Attributes Using Late Binding

    • Putting Reflection, Late Binding, and Custom Attributes in Perspective

    • Building an Extendable Application

      • Building CommonSnappableTypes.dll

      • Building the C# Snap-In

      • Building the Visual Basic Snap-In

      • Building an Extendable Windows Forms Application

    • Summary

  • Dynamic Types and the Dynamic Language Runtime

    • The Role of the C# dynamic Keyword

      • Calling Members on Dynamically Declared Data

      • The Role of the Microsoft.CSharp.dll Assembly

      • The Scope of the dynamic Keyword

      • Limitations of the dynamic Keyword

      • Practical Uses of the dynamic Keyword

    • The Role of the Dynamic Language Runtime (DLR)

      • The Role of Expression Trees

      • The Role of the System.Dynamic Namespace

      • Dynamic Runtime Lookup of Expression Trees

    • Simplifying Late-Bound Calls Using Dynamic Types

      • Leveraging the dynamic Keyword to Pass Arguments

    • Simplifying COM Interoperability Using Dynamic Data

      • The Role of Primary Interop Assemblies (PIAs)

      • Embedding Interop Metadata

      • Common COM Interop Pain Points

    • COM Interop Using C# Dynamic Data

      • COM interop Without C# Dynamic Data

    • Summary

  • Processes, AppDomains, and Object Contexts

    • The Role of a Windows Process

      • The Role of Threads

    • Interacting with Processes Under the .NET Platform

      • Enumerating Running Processes

      • Investigating a Specific Process

      • Investigating a Process’s Thread Set

      • Investigating a Process’s Module Set

      • Starting and Stopping Processes Programmatically

      • Controlling Process Startup Using the ProcessStartInfo Class

    • Understanding .NET Application Domains

      • The System.AppDomain Class

    • Interacting with the Default Application Domain

      • Enumerating Loaded Assemblies

      • Receiving Assembly Load Notifications

    • Creating New Application Domains

      • Loading Assemblies into Custom Application Domains

      • Programmatically Unloading AppDomains

    • Understanding Object Context Boundaries

      • Context-Agile and Context-Bound Types

      • Defining a Context-Bound Object

      • Inspecting an Object’s Context

    • Summarizing Processes, AppDomains, and Context

    • Summary

  • Understanding CIL and the Role of Dynamic Assemblies

    • Reasons for Learning the Grammar of CIL

    • Examining CIL Directives, Attributes, and Opcodes

      • The Role of CIL Directives

      • The Role of CIL Attributes

      • The Role of CIL Opcodes

      • The CIL Opcode/CIL Mnemonic Distinction

    • Pushing and Popping: The Stack-Based Nature of CIL

    • Understanding Round-Trip Engineering

      • The Role of CIL Code Labels

      • Interacting with CIL: Modifying an *.il File

      • Compiling CIL Code Using ilasm.exe

      • The Role of peverify.exe

    • Understanding CIL Directives and Attributes

      • Specifying Externally Referenced Assemblies in CIL

      • Defining the Current Assembly in CIL

      • Defining Namespaces in CIL

      • Defining Class Types in CIL

      • Defining and Implementing Interfaces in CIL

      • Defining Structures in CIL

      • Defining Enums in CIL

      • Defining Generics in CIL

      • Compiling the CILTypes.il file

    • .NET Base Class Library, C#, and CIL Data Type Mappings

    • Defining Type Members in CIL

      • Defining Field Data in CIL

      • Defining Type Constructors in CIL

      • Defining Properties in CIL

      • Defining Member Parameters

    • Examining CIL Opcodes

      • The .maxstack Directive

      • Declaring Local Variables in CIL

      • Mapping Parameters to Local Variables in CIL

      • The Hidden this Reference

      • Representing Iteration Constructs in CIL

    • Building a .NET Assembly with CIL

      • Building CILCars.dll

      • Building CILCarClient.exe

    • Understanding Dynamic Assemblies

      • Exploring the System.Reflection.Emit Namespace

      • The Role of the System.Reflection.Emit.ILGenerator

      • Emitting a Dynamic Assembly

      • Emitting the Assembly and Module Set

      • The Role of the ModuleBuilder Type

      • Emitting the HelloClass Type and the String Member Variable

      • Emitting the Constructors

      • Emitting the SayHello() Method

      • Using the Dynamically Generated Assembly

    • Summary

  • Multithreaded, Parallel, and Async Programming

    • The Process/AppDomain/Context/Thread Relationship

      • The Problem of Concurrency

      • The Role of Thread Synchronization

    • A Brief Review of the .NET Delegate

    • The Asynchronous Nature of Delegates

      • The BeginInvoke() and EndInvoke() Methods

      • The System.IAsyncResult Interface

    • Invoking a Method Asynchronously

      • Synchronizing the Calling Thread

      • The Role of the AsyncCallback Delegate

      • The Role of the AsyncResult Class

      • Passing and Receiving Custom State Data

    • The System.Threading Namespace

    • The System.Threading.Thread Class

      • Obtaining Statistics About the Current Thread of Execution

      • The Name Property

      • The Priority Property

    • Manually Creating Secondary Threads

      • Working with the ThreadStart Delegate

      • Working with the ParameterizedThreadStart Delegate

      • The AutoResetEvent Class

      • Foreground Threads and Background Threads

    • The Issue of Concurrency

      • Synchronization Using the C# lock Keyword

      • Synchronization Using the System.Threading.Monitor Type

      • Synchronization Using the System.Threading.Interlocked Type

      • Synchronization Using the [Synchronization] Attribute

    • Programming with Timer Callbacks

    • Understanding the CLR ThreadPool

    • Parallel Programming Using the Task Parallel Library

      • The System.Threading.Tasks Namespace

      • The Role of the Parallel Class

      • Data Parallelism with the Parallel Class

      • Accessing UI Elements on Secondary Threads

      • The Task Class

      • Handling Cancellation Request

      • Task Parallelism Using the Parallel Class

    • Parallel LINQ Queries (PLINQ)

      • Opting in to a PLINQ Query

      • Cancelling a PLINQ Query

    • Asynchronous Calls Under .NET 4.5

      • A First Look at the C# async and await Keywords

      • Naming Conventions for Async Methods

      • Async Methods Returning Void

      • Async Methods with Multiple Awaits

      • Retrofitting the AddWithThreads Example Using Asycn/Await

    • Summary

  • File I/O and Object Serialization

    • Exploring the System.IO Namespace

    • The Directory(Info) and File(Info) Types

      • The Abstract FileSystemInfo Base Class

    • Working with the DirectoryInfo Type

      • Enumerating Files with the DirectoryInfo Type

      • Creating Subdirectories with the DirectoryInfo Type

    • Working with the Directory Type

    • Working with the DriveInfo Class Type

    • Working with the FileInfo Class

      • The FileInfo.Create() Method

      • The FileInfo.Open() Method

      • The FileInfo.OpenRead() and FileInfo.OpenWrite() Methods

      • The FileInfo.OpenText() Method

      • The FileInfo.CreateText() and FileInfo.AppendText() Methods

    • Working with the File Type

      • Additional File-Centric Members

    • The Abstract Stream Class

      • Working with FileStreams

    • Working with StreamWriters and StreamReaders

      • Writing to a Text File

      • Reading from a Text File

      • Directly Creating StreamWriter/StreamReader Types

    • Working with StringWriters and StringReaders

    • Working with BinaryWriters and BinaryReaders

    • Watching Files Programmatically

    • Understanding Object Serialization

      • The Role of Object Graphs

    • Configuring Objects for Serialization

      • Defining Serializable Types

      • Public Fields, Private Fields, and Public Properties

    • Choosing a Serialization Formatter

      • The IFormatter and IRemotingFormatter Interfaces

      • Type Fidelity Among the Formatters

    • Serializing Objects Using the BinaryFormatter

      • Deserializing Objects Using the BinaryFormatter

    • Serializing Objects Using the SoapFormatter

    • Serializing Objects Using the XmlSerializer

      • Controlling the Generated XML Data

    • Serializing Collections of Objects

    • Customizing the Soap/Binary Serialization Process

      • A Deeper Look at Object Serialization

      • Customizing Serialization Using ISerializable

      • Customizing Serialization Using Attributes

    • Summary

  • ADO.NET Part I: The Connected Layer

    • A High-Level Definition of ADO.NET

      • The Three Faces of ADO.NET

    • Understanding ADO.NET Data Providers

      • The Microsoft-Supplied ADO.NET Data Providers

      • A Word Regarding System.Data.OracleClient.dll

      • Obtaining Third-Party ADO.NET Data Providers

    • Additional ADO.NET Namespaces

    • The Types of the System.Data Namespace

      • The Role of the IDbConnection Interface

      • The Role of the IDbTransaction Interface

      • The Role of the IDbCommand Interface

      • The Role of the IDbDataParameter and IDataParameter Interfaces

      • The Role of the IDbDataAdapter and IDataAdapter Interfaces

      • The Role of the IDataReader and IDataRecord Interfaces

    • Abstracting Data Providers Using Interfaces

      • Increasing Flexibility Using Application Configuration Files

    • Creating the AutoLot Database

      • Creating the Inventory Table

      • Adding Test Records to the Inventory Table

      • Authoring the GetPetName() Stored Procedure

      • Creating the Customers and Orders Tables

      • Visually Creating Table Relationships

    • The ADO.NET Data Provider Factory Model

      • A Complete Data Provider Factory Example

      • A Potential Drawback with the Data Provider Factory Model

      • The <connectionStrings> Element

    • Understanding the Connected Layer of ADO.NET

      • Working with Connection Objects

      • Working with ConnectionStringBuilder Objects

      • Working with Command Objects

    • Working with Data Readers

      • Obtaining Multiple Result Sets Using a Data Reader

    • Building a Reusable Data Access Library

      • Adding the Connection Logic

      • Adding the Insertion Logic

      • Adding the Deletion Logic

      • Adding the Update Logic

      • Adding the Selection Logic

      • Working with Parameterized Command Objects

      • Executing a Stored Procedure

    • Creating a Console UI–Based Front End

      • Implementing the Main() Method

      • Implementing the ShowInstructions() Method

      • Implementing the ListInventory() Method

      • Implementing the DeleteCar() Method

      • Implementing the InsertNewCar() Method

      • Implementing the UpdateCarPetName() Method

      • Implementing LookUpPetName()

    • Understanding Database Transactions

      • Key Members of an ADO.NET Transaction Object

      • Adding a CreditRisks Table to the AutoLot Database

      • Adding a Transaction Method to InventoryDAL

      • Testing Your Database Transaction

    • Summary

  • ADO.NET Part II: The Disconnected Layer

    • Understanding the Disconnected Layer of ADO.NET

    • Understanding the Role of the DataSet

      • Key Properties of the DataSet

      • Key Methods of the DataSet

      • Building a DataSet

    • Working with DataColumns

      • Building a DataColumn

      • Enabling Autoincrementing Fields

      • Adding DataColumn Objects to a DataTable

    • Working with DataRows

      • Understanding the RowState Property

      • Understanding the DataRowVersion Property

    • Working with DataTables

      • Inserting DataTables into DataSets

      • Obtaining Data in a DataSet

      • Processing DataTable Data Using DataTableReader Objects

      • Serializing DataTable/DataSet Objects As XML

      • Serializing DataTable/DataSet Objects in a Binary Format

    • Binding DataTable Objects to Windows Forms GUIs

      • Hydrating a DataTable from a Generic List<T>

      • Deleting Rows from a DataTable

      • Selecting Rows Based on Filter Criteria

      • Updating Rows Within a DataTable

      • Working with the DataView Type

    • Working with Data Adapters

      • A Simple Data Adapter Example

      • Mapping Database Names to Friendly Names

    • Adding Disconnection Functionality to AutoLotDAL.dll

      • Defining the Initial Class Type

      • Configuring the Data Adapter Using the SqlCommandBuilder

      • Implementing GetAllInventory()

      • Implementing UpdateInventory()

      • Setting Your Version Number

      • Testing the Disconnected Functionality

    • Multitabled DataSet Objects and Data Relationships

      • Prepping the Data Adapters

      • Building the Table Relationships

      • Updating the Database Tables

      • Navigating Between Related Tables

    • The Windows Forms Database Designer Tools

      • Visually Designing the DataGridView

      • The Generated App.config File

      • Examining the Strongly Typed DataSet

      • Examining the Strongly Typed DataTable

      • Examining the Strongly Typed DataRow

      • Examining the Strongly Typed Data Adapter

      • Completing the Windows Forms Application

    • Isolating Strongly Typed Database Code into a Class Library

      • Viewing the Generated Code

      • Selecting Data with the Generated Code

      • Inserting Data with the Generated Code

      • Deleting Data with the Generated Code

      • Invoking a Stored Procedure Using the Generated Code

    • Programming with LINQ to DataSet

      • The Role of the DataSet Extensions Library

      • Obtaining a LINQ-Compatible DataTable

      • The Role of the DataRowExtensions.Field<T>() Extension Method

      • Hydrating New DataTables from LINQ Queries

    • Summary

  • ADO.NET Part III: The Entity Framework

    • Understanding the Role of Entity Framework

      • The Role of Entities

      • The Building Blocks of the Entity Framework

    • Building and Analyzing Your First EDM

    • Programming Against the Conceptual Model

    • AutoLotDAL Version Four, Now with Entities

      • The Role of Navigation Properties

      • Using Navigation Properties within LINQ to Entity Queries

      • Invoking a Stored Procedure

    • Data Binding Entities to Windows Forms GUIs

      • Adding the Data-Binding Code

    • Going Forward with .NET Data-Access APIs

    • Summary

  • Introducing LINQ to XML

    • A Tale of Two XML APIs

      • LINQ to XML As a Better DOM

      • VB Literal Syntax As a Better LINQ to XML

    • Members of the System.Xml.Linq Namespace

      • The LINQ to XML Axis Methods

      • The Oddness of XName (and XNamespace)

    • Working with XElement and XDocument

      • Generating Documents from Arrays and Containers

      • Loading and Parsing XML Content

    • Manipulating an In-Memory XML Document

      • Building the UI of the LINQ to XML App

      • Import the Inventory.xml File

      • Defining a LINQ to XML Helper Class

      • Attaching the UI to Your Helper Class

    • Summary

  • Introducing Windows Communication Foundation

    • A Potpourri of Distributed Computing APIs

      • The Role of DCOM

      • The Role of COM+/Enterprise Services

      • The Role of MSMQ

      • The Role of .NET Remoting

      • The Role of XML Web Services

    • The Role of WCF

      • An Overview of WCF Features

      • An Overview of Service-Oriented Architecture

      • WCF: The Bottom Line

    • Investigating the Core WCF Assemblies

    • The Visual Studio WCF Project Templates

      • The WCF Service Web Site Project Template

    • The Basic Composition of a WCF Application

    • The ABCs of WCF

      • Understanding WCF Contracts

      • Understanding WCF Bindings

      • Understanding WCF Addresses

    • Building a WCF Service

      • The [ServiceContract] Attribute

      • The [OperationContract] Attribute

      • Service Types As Operational Contracts

    • Hosting the WCF Service

      • Establishing the ABCs Within an App.config File

      • Coding Against the ServiceHost Type

      • Specifying Base Addresses

      • Details of the ServiceHost Type

      • Details of the <system.serviceModel> Element

      • Enabling Metadata Exchange

    • Building the WCF Client Application

      • Generating Proxy Code Using svcutil.exe

      • Generating Proxy Code Using Visual Studio

      • Configuring a TCP-Based Binding

    • Simplifying Configuration Settings

      • Leveraging Default Endpoints

      • Exposing a Single WCF Service Using Multiple Bindings

      • Changing Settings for a WCF Binding

      • Leveraging the Default MEX Behavior Configuration

      • Refreshing the Client Proxy and Selecting the Binding

    • Using the WCF Service Library Project Template

      • Building a Simple Math Service

      • Testing the WCF Service with WcfTestClient.exe

      • Altering Configuration Files Using SvcConfigEditor.exe

    • Hosting the WCF Service Within a Windows Service

      • Specifying the ABCs in Code

      • Enabling MEX

      • Creating a Windows Service Installer

      • Installing the Windows Service

    • Invoking a Service Asynchronously from the Client

    • Designing WCF Data Contracts

      • Using the Web-Centric WCF Service Project Template

      • Implementing the Service Contract

      • The Role of the *.svc File

      • Examining the Web.config File

      • Testing the Service

    • Summary

  • Introducing Windows Workflow Foundation

    • Defining a Business Process

      • The Role of WF

    • Building a Simple Workflow

    • The Workflow Runtime

      • Hosting a Workflow Using WorkflowInvoker

      • Hosting a Workflow Using WorkflowApplication

      • Recap of Your First Workflow

    • Examining the Workflow Activities

      • Control Flow Activities

      • Flowchart Activities

      • Messaging Activities

      • The State Machine Activities

      • The Runtime and Primitives Activities

      • The Transaction Activities

      • The Collection and Error Handling Activities

    • Building a Flowchart Workflow

      • Connecting Activities in a Flowchart

      • Working with the InvokeMethod Activity

      • Defining Workflow-Wide Variables

      • Working with the FlowDecision Activity

      • Working with the TerminateWorkflow Activity

      • Building the “True” Condition

      • Working with the ForEach<T> Activity

      • Completing the Application

      • Reflecting on What We Have Done

    • Building a Sequence Workflow (in a Dedicated DLL)

      • Defining the Initial Project

      • Importing Assemblies and Namespaces

      • Defining the Workflow Arguments

      • Defining Workflow Variables

      • Working with the Assign Activity

      • Working with the If and Switch Activities

      • Building a Custom Code Activity

    • Consuming the Workflow Library

      • Retrieving the Workflow Output Argument

    • Summary

  • Introducing Windows Presentation Foundation and XAML

    • The Motivation Behind WPF

      • Unifying Diverse APIs

      • Providing a Separation of Concerns via XAML

      • Providing an Optimized Rendering Model

      • Simplifying Complex UI Programming

    • The Various Flavors of WPF

      • Traditional Desktop Applications

      • Navigation-Based WPF Applications

      • XBAP Applications

      • The WPF/Silverlight Relationship

    • Investigating the WPF Assemblies

      • The Role of the Application Class

      • The Role of the Window Class

    • Building a WPF Application Without XAML

      • Creating a Strongly Typed Window

      • Creating a Simple User Interface

      • Interacting with Application-Level Data

      • Handling the Closing of a Window Object

      • Intercepting Mouse Events

      • Intercepting Keyboard Events

    • Building a WPF Application Using Only XAML

      • Defining a Window Object in XAML

      • Defining the Application Object in XAML

      • Processing the XAML Files Using msbuild.exe

    • Transforming Markup into a .NET Assembly

      • Mapping the Window XAML Markup to C# Code

      • The Role of BAML

      • Mapping the Application XAML Markup to C# Code

      • XAML-to-Assembly Process Summary

    • Understanding the Syntax of WPF XAML

      • Introducing Kaxaml

      • XAML XML Namespaces and XAML “Keywords”

      • Controlling Class and Member Variable Visibility

      • XAML Elements, XAML Attributes, and Type Converters

      • Understanding XAML Property-Element Syntax

      • Understanding XAML Attached Properties

      • Understanding XAML Markup Extensions

    • Building a WPF Application Using Code-Behind Files

      • Adding a Code File for the MainWindow Class

      • Adding a Code File for the MyApp Class

      • Processing the Code Files with msbuild.exe

    • Building WPF Applications Using Visual Studio

      • The WPF Project Templates

      • The Toolbox and XAML Designer/Editor

      • Setting Properties Using the Properties Window

      • Handling Events Using the Properties Window

      • Handling Events in the XAML Editor

      • The Document Outline Window

      • Viewing the AutoGenerated Code Files

    • Building a Custom XAML Editor with Visual Studio

      • Designing the GUI of Our Window

      • Implementing the Loaded Event

      • Implementing the Button’s Click Event

      • Implementing the Closed Event

      • Testing Your Application

      • Exploring the WPF Documentation

    • Summary

  • Programming with WPF Controls

    • A Survey of the Core WPF Controls

      • The WPF Ink Controls

      • The WPF Document Controls

      • WPF Common Dialog Boxes

      • The Details Are in the Documentation

    • A Brief Review of the Visual Studio WPF Designer

      • Working with WPF Controls Using Visual Studio

      • Working with the Document Outline Editor

    • Controlling Content Layout Using Panels

      • Positioning Content Within Canvas Panels

      • Positioning Content Within WrapPanel Panels

      • Positioning Content Within StackPanel Panels

      • Positioning Content Within Grid Panels

      • Positioning Content Within DockPanel Panels

      • Enabling Scrolling for Panel Types

      • Configuring Panels Using the Visual Studio Designers

    • Building a Window’s Frame Using Nested Panels

      • Building the Menu System

      • Building the ToolBar

      • Building the StatusBar

      • Finalizing the UI Design

      • Implementing the MouseEnter/MouseLeave Event Handlers

      • Implementing the Spell Checking Logic

    • Understanding WPF Commands

      • The Intrinsic Command Objects

      • Connecting Commands to the Command Property

      • Connecting Commands to Arbitrary Actions

      • Working with the Open and Save Commands

    • A Deeper Look at WPF APIs and Controls

      • Working with the TabControl

    • Building the Ink API Tab

      • Designing the ToolBar

      • The RadioButton Control

      • Handling Events for the Ink API Tab

      • The InkCanvas Control

      • The ComboBox Control

      • Saving, Loading, and Clearing InkCanvas Data

    • Introducing the Documents API

      • Block Elements and Inline Elements

      • Document Layout Managers

    • Building the Documents Tab

      • Populating a FlowDocument Using Code

      • Enabling Annotations and Sticky Notes

      • Saving and Loading a Flow Document

    • Introducing the WPF Data-Binding Model

      • Building the Data Binding Tab

      • Establishing Data Bindings Using Visual Studio

      • The DataContext Property

      • Data Conversion Using IValueConverter

      • Establishing Data Bindings in Code

      • Building the DataGrid Tab

    • Summary

  • WPF Graphics Rendering Services

    • Understanding WPF’s Graphical Rendering Services

      • WPF Graphical Rendering Options

    • Rendering Graphical Data Using Shapes

      • Adding Rectangles, Ellipses, and Lines to a Canvas

      • Removing Rectangles, Ellipses, and Lines from a Canvas

      • Working with Polylines and Polygons

      • Working with Paths

    • WPF Brushes and Pens

      • Configuring Brushes Using Visual Studio

      • Configuring Brushes in Code

      • Configuring Pens

    • Applying Graphical Transformations

      • A First Look at Transformations

      • Transforming Our Canvas Data

    • Working with the Visual Studio Transform Editor

      • Building the Initial Layout

      • Applying Transformations at Design Time

      • Transforming the Canvas in Code

    • Rendering Graphical Data Using Drawings and Geometries

      • Building a DrawingBrush Using Geometries

      • Painting with the DrawingBrush

      • Containing Drawing Types in a DrawingImage

    • The Role of Expression Design

      • Exporting a Sample Design File As XAML

      • Importing the Graphical Data into a WPF Project

      • Interacting with the Bear

    • Rendering Graphical Data Using the Visual Layer

    • Summary

  • WPF Resources, Animations, and Styles

    • Understanding the WPF Resource System

      • Working with Binary Resources

    • Working with Object (Logical) Resources

      • The Role of the Resources Property

      • Defining Window-Wide Resources

      • The Markup Extension

      • The {DynamicResource} Markup Extension

      • Application-Level Resources

      • Defining Merged Resource Dictionaries

      • Defining a Resource-Only Assembly

    • Understanding WPF’s Animation Services

      • The Role of the Animation Class Types

      • The To, From, and By Properties

      • The Role of the Timeline Base Class

      • Authoring an Animation in C# Code

      • Controlling the Pace of an Animation

      • Reversing and Looping an Animation

    • Authoring Animations in XAML

      • The Role of Storyboards

      • The Role of Event Triggers

      • Animation Using Discrete Key Frames

    • Understanding the Role of WPF Styles

      • Defining and Applying a Style

      • Overriding Style Settings

      • Automatically Applying a Style with TargetType

      • Subclassing Existing Styles

      • The Role of Unnamed Styles

      • Defining Styles with Triggers

      • Defining Styles with Multiple Triggers

      • Animated Styles

      • Assigning Styles Programmatically

    • Summary

  • Dependency Properties, Routed Events, and Templates

    • Understanding the Role of Dependency Properties

      • Examining an Existing Dependency Property

      • Important Notes Regarding CLR Property Wrappers

    • Building a Custom Dependency Property

      • Adding a Data Validation Routine

      • Responding to the Property Change

    • Understanding Routed Events

      • The Role of Routed Bubbling Events

      • Continuing or Halting Bubbling

      • The Role of Routed Tunneling Events

    • Logical Trees, Visual Trees, and Default Templates

      • Programmatically Inspecting a Logical Tree

      • Programmatically Inspecting a Visual Tree

      • Programmatically Inspecting a Control’s Default Template

    • Building a Control Template with the Trigger Framework

      • Templates As Resources

      • Incorporating Visual Cues Using Triggers

      • The Role of the {TemplateBinding} Markup Extension

      • The Role of ContentPresenter

      • Incorporating Templates into Styles

    • Summary

  • Introducing ASP.NET Web Forms

    • The Role of HTTP

      • The HTTP Request/Response Cycle

      • HTTP Is a Stateless Protocol

    • Understanding Web Applications and Web Servers

      • The Role of IIS Virtual Directories

      • The ASP.NET Development Web Server

    • The Role of HTML

      • HTML Document Structure

      • The Role of an HTML Form

      • The Visual Studio HTML Designer Tools

      • Building an HTML Form

    • The Role of Client-Side Scripting

      • A Client-Side Scripting Example

    • Posting Back to the Web Server

      • Postbacks Under ASP.NET

    • An Overview of the ASP.NET API

      • Major Features of ASP.NET 2.0 and Higher

      • Major Features of ASP.NET 3.5 (and .NET 3.5 SP1) and Higher

      • Major Features of ASP.NET 4.0 and 4.5

    • Building a Single-File ASP.NET Web Page

      • Referencing AutoLotDAL.dll

      • Designing the UI

      • Adding the Data Access Logic

      • The Role of ASP.NET Directives

      • Analyzing the “Script” Block

      • Analyzing the ASP.NET Control Declarations

    • Building an ASP.NET Web Page Using Code Files

      • Referencing the AutoLotDAL.dll Assembly

      • Updating the Code File

      • Debugging and Tracing ASP.NET Pages

    • ASP.NET Web Sites vs. ASP.NET Web Applications

    • The ASP.NET Web Site Directory Structure

      • Referencing Assemblies

      • The Role of the App_Code Folder

    • The Inheritance Chain of the Page Type

    • Interacting with the Incoming HTTP Request

      • Obtaining Browser Statistics

      • Access to Incoming Form Data

      • The IsPostBack Property

    • Interacting with the Outgoing HTTP Response

      • Emitting HTML Content

      • Redirecting Users

    • The Life Cycle of an ASP.NET Web Page

      • The Role of the AutoEventWireup Attribute

      • The Error Event

    • The Role of the web.config File

      • The ASP.NET Web Site Administration Utility

    • Summary

  • ASP.NET Web Controls, Master Pages, and Themes

    • Understanding the Nature of Web Controls

      • Understanding Server-Side Event Handling

      • The AutoPostBack Property

    • The Control and WebControl Base Classes

      • Enumerating Contained Controls

      • Dynamically Adding and Removing Controls

      • Interacting with Dynamically Created Controls

      • Functionality of the WebControl Base Class

    • Major Categories of ASP.NET Web Controls

      • A Brief Word Regarding System.Web.UI.HtmlControls

      • Web Control Documentation

    • Building the ASP.NET Cars Web Site

      • Working with ASP.NET Master Pages

      • Defining the Default Content Page

      • Designing the Inventory Content Page

      • Designing the Build-a-Car Content Page

    • The Role of the Validation Controls

      • Enabling Client-Side JavaScript Validation Support

      • The RequiredFieldValidator

      • The RegularExpressionValidator

      • The RangeValidator

      • The CompareValidator

      • Creating Validation Summaries

      • Defining Validation Groups

    • Working with Themes

      • Understanding *.skin Files

      • Applying Site-Wide Themes

      • Applying Themes at the Page Level

      • The SkinID Property

      • Assigning Themes Programmatically

    • Summary

  • ASP.NET State Management Techniques

    • The Issue of State

    • ASP.NET State Management Techniques

    • Understanding the Role of ASP.NET View State

      • Demonstrating View State

      • Adding Custom View State Data

    • The Role of the Global.asax File

      • The Global Last-Chance Exception Event Handler

      • The HttpApplication Base Class

    • Understanding the Application/Session Distinction

      • Maintaining Application-Level State Data

      • Modifying Application Data

      • Handling Web Application Shutdown

    • Working with the Application Cache

      • Fun with Data Caching

      • Modifying the *.aspx File

    • Maintaining Session Data

      • Additional Members of HttpSessionState

    • Understanding Cookies

      • Creating Cookies

      • Reading Incoming Cookie Data

    • The Role of the <sessionState> Element

      • Storing Session Data in the ASP.NET Session State Server

      • Storing Session Data in a Dedicated Database

    • Introducing the ASP.NET Profile API

      • The ASPNETDB.mdf Database

      • Defining a User Profile Within web.config

      • Accessing Profile Data Programmatically

      • Grouping Profile Data and Persisting Custom Objects

    • Summary

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T, U

    • V

    • W

    • X, Y, Z

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan