Pro C# 2010 and the .NET 4 Platform (eBook)
1752 Seiten
Apress (Verlag)
978-1-4302-2550-8 (ISBN)
The first edition of this book was released at the 2001 Tech-Ed conference in Atlanta, Georgia. At that time, the .NET platform was still a beta product, and in many ways, so was this book. This is not to say that the early editions of this text did not have merit-after all, the book was a 2002 Jolt Award finalist and it won the 2003 Referenceware Excellence Award. However, over the years that author Andrew Troelsen spent working with the common language runtime (CLR), he gained a much deeper understanding of the .NET platform and the subtleties of the C# programming language, and he feels that this fifth edition of the book is as close to a 'final release' as he's come yet.
This new edition has been comprehensively revised and rewritten to make it accurately reflect the C# 4 language specification for the .NET 4 platform. You'll find new chapters covering the important concepts of dynamic lookups, named and optional arguments, Parallel LINQ (PLINQ), improved COM interop, and variance for generics.
If you're checking out this book for the first time, do understand that it's targeted at experienced software professionals and/or graduate students of computer science (so don't expect three chapters on iteration or decision constructs!). The mission of this text is to provide you with a rock-solid foundation in the C# programming language and the core aspects of the .NET platform (assemblies, remoting, Windows Forms, Web Forms, ADO.NET, XML web services, etc.). Once you digest the information presented in these 25 chapters, you'll be in a perfect position to apply this knowledge to your specific programming assignments, and you'll be well equipped to explore the .NET universe on your own terms.
Andrew Troelsen is a partner, trainer, and consultant at Intertech Inc., and is a leading authority on both .NET and COM. His book Pro C# 2005 and the .NET 2.0 Platform won the prestigious 2003 Referenceware Excellence Award and is in its third edition. Also of note are his earlier five-star treatment of traditional COM in the bestselling Developer's Workshop to COM and ATL mirrored in his book, COM and .NET Interoperability, and his top-notch investigation of VB .NET in Visual Basic .NET and the .NET Platform: An Advanced Guide. Troelsen has a degree in mathematical linguistics and South Asian studies from the University of Minnesota, and is a frequent speaker at numerous .NET-related conferences. He currently lives in Minneapolis with his wife, Amanda, and spends his free time investigating .NET and waiting for the Wild to win the Stanley Cup. You can check out his blog at AndrewTroelsen.blogspot.com.
The first edition of this book was released at the 2001 Tech-Ed conference in Atlanta, Georgia. At that time, the .NET platform was still a beta product, and in many ways, so was this book. This is not to say that the early editions of this text did not have merit-after all, the book was a 2002 Jolt Award finalist and it won the 2003 Referenceware Excellence Award. However, over the years that author Andrew Troelsen spent working with the common language runtime (CLR), he gained a much deeper understanding of the .NET platform and the subtleties of the C# programming language, and he feels that this fifth edition of the book is as close to a "e;final release"e; as he's come yet. This new edition has been comprehensively revised and rewritten to make it accurately reflect the C# 4 language specification for the .NET 4 platform. You ll find new chapters covering the important concepts of dynamic lookups, named and optional arguments, Parallel LINQ (PLINQ), improved COM interop, and variance for generics. If you re checking out this book for the first time, do understand that it's targeted at experienced software professionals and/or graduate students of computer science (so don't expect three chapters on iteration or decision constructs!). The mission of this text is to provide you with a rock-solid foundation in the C# programming language and the core aspects of the .NET platform (assemblies, remoting, Windows Forms, Web Forms, ADO.NET, XML web services, etc.). Once you digest the information presented in these 25 chapters, you ll be in a perfect position to apply this knowledge to your specific programming assignments, and you ll be well equipped to explore the .NET universe on your own terms.
Andrew Troelsen is a partner, trainer, and consultant at Intertech Inc., and is a leading authority on both .NET and COM. His book Pro C# 2005 and the .NET 2.0 Platform won the prestigious 2003 Referenceware Excellence Award and is in its third edition. Also of note are his earlier five-star treatment of traditional COM in the bestselling Developer's Workshop to COM and ATL mirrored in his book, COM and .NET Interoperability, and his top-notch investigation of VB .NET in Visual Basic .NET and the .NET Platform: An Advanced Guide. Troelsen has a degree in mathematical linguistics and South Asian studies from the University of Minnesota, and is a frequent speaker at numerous .NET-related conferences. He currently lives in Minneapolis with his wife, Amanda, and spends his free time investigating .NET and waiting for the Wild to win the Stanley Cup. You can check out his blog at AndrewTroelsen.blogspot.com.
Title Page
1
Copyright Page
2
Contents at a Glance 4
Table of Contents
7
About the Author 24
About the Technical Reviewer 25
Acknowledgments 26
Introduction 27
We’re a Team, You and I 28
An Overview of This Book 28
Part 1: Introducing C# and the .NET Platform 29
Part 2: Core C# Programming Constructs 29
Part 3: Advanced C# Programming Constructs 30
Part 4: Programming with .NET Assemblies 31
Part 5: Introducing the .NET Base Class Libraries 32
Part 6: Building Desktop User Interfaces using WPF 34
Part 7: Building Web Applications with ASP.NET 35
Part 8: Appendixes 36
Obtaining This Book’s Source Code 36
Obtaining Updates for This Book 37
Contacting Me 37
PART 1 Introducing C# and the .NET Platform
38
CHAPTER 1 The Philosophy of .NET
39
Understanding the Previous State of Affairs 39
Life As a C/Windows API Programmer 40
Life As a C++/MFC Programmer 40
Life As a Visual Basic 6.0 Programmer 40
Life As a Java Programmer 41
Life As a COM Programmer 41
The Complexity of COM Data Type Representation 42
The .NET Solution 42
Introducing the Building Blocks of the .NET Platform (the CLR, CTS, and CLS)
43
The Role of the Base Class Libraries 44
What C# Brings to the Table 44
Additional .NET-Aware Programming Languages 46
Life in a Multi-Language World 48
An Overview of .NET Assemblies 48
Single-File and Multi-File Assemblies 50
The Role of the Common Intermediate Language 50
Benefits of CIL 52
Compiling CIL to Platform-Specific Instructions 53
The Role of .NET Type Metadata 53
The Role of the Assembly Manifest 54
Understanding the Common Type System 55
CTS Class Types 55
CTS Interface Types 56
CTS Structure Types 56
CTS Enumeration Types 57
CTS Delegate Types 57
CTS Type Members 58
Intrinsic CTS Data Types 58
Understanding the Common Language Specification 59
Ensuring CLS Compliance 61
Understanding the Common Language Runtime 61
The Assembly/Namespace/Type Distinction 63
The Role of the Microsoft Root Namespace 66
Accessing a Namespace Programmatically 66
Referencing External Assemblies 68
Exploring an Assembly Using ildasm.exe 69
Viewing CIL Code 70
Viewing Type Metadata 70
Viewing Assembly Metadata (aka the Manifest) 71
Exploring an Assembly Using Reflector 71
Deploying the .NET Runtime 72
The .NET Client Profile Runtime 73
The Platform-Independent Nature of .NET 73
Summary 75
CHAPTER 2 Building C# Applications
76
The Role of the .NET Framework 4.0 SDK 76
The Visual Studio 2010 Command Prompt 77
Building C# Applications Using csc.exe 77
Specifying Input and Output Targets 78
Referencing External Assemblies 80
Referencing Multiple External Assemblies 81
Compiling Multiple Source Files 81
Working with C# Response Files 82
The Default Response File (csc.rsp) 83
Building .NET Applications Using Notepad++ 84
Building .NET Applications Using SharpDevelop 85
Building a Simple Test Project 86
Building .NET Applications Using Visual C# 2010 Express 88
Some Unique Features of Visual C# 2010 Express 88
Building .NET Applications Using Visual Studio 2010 89
Some Unique Features of Visual Studio 2010 90
Targeting the .NET Framework Using the New Project Dialog Box 91
Using the Solution Explorer Utility 91
Referencing External Assemblies 92
Viewing Project Properties 93
The Class View Utility 93
The Object Browser Utility 95
Integrated Support for Code Refactoring 95
Code Expansions and Surround With Technology 98
The Visual Class Designer 99
The Integrated .NET Framework 4.0 SDK Documentation System 102
Summary 104
PART 2 Core C# Programming Constructs
105
CHAPTER 3 Core C# Programming Constructs, Part I
106
The Anatomy of a Simple C# Program 106
Variations on the Main() Method 108
Specifying an Application Error Code 109
Processing Command-Line Arguments 110
Specifying Command-Line Arguments with Visual Studio 2010 112
An Interesting Aside: Some Additional Members of the System.Environment Class
112
The System.Console Class 114
Basic Input and Output with the Console Class 115
Formatting Console Output 116
Formatting Numerical Data 117
Formatting Numerical Data Beyond Console Applications 118
System Data Types and C# Shorthand Notation 119
Variable Declaration and Initialization 121
Intrinsic Data Types and the new Operator 122
The Data Type Class Hierarchy 123
Members of Numerical Data Types 125
Members of System.Boolean 126
Members of System.Char 126
Parsing Values from String Data 127
System.DateTime and System.TimeSpan 128
The .NET 4.0 System.Numerics Namespace 128
Working with String Data 130
Basic String Manipulation 131
String Concatenation 132
Escape Characters 133
Defining Verbatim Strings 134
Strings and Equality 135
Strings Are Immutable 135
The System.Text.StringBuilder Type 137
Narrowing and Widening Data Type Conversions 139
Trapping Narrowing Data Conversions 141
Setting Project-wide Overflow Checking 143
The unchecked Keyword 144
The Role of System.Convert 145
Understanding Implicitly Typed Local Variables 145
Restrictions on Implicitly Typed Variables 147
Implicit Typed Data Is Strongly Typed Data 148
Usefulness of Implicitly Typed Local Variables 149
C# Iteration Constructs 150
The for Loop 150
The foreach Loop 151
Use of var Within foreach Constructs 151
The while and do/while Looping Constructs 152
Decision Constructs and the Relational/Equality Operators 152
The if/else Statement 153
The switch Statement 154
Summary 155
CHAPTER 4 Core C# Programming Constructs, Part II
157
Methods and Parameter Modifiers 157
The Default Parameter-Passing Behavior 158
The out Modifier 159
The ref Modifier 160
The params Modifier 162
Defining Optional Parameters 163
Invoking Methods using Named Parameters 165
Understanding Method Overloading 167
Understanding C# Arrays 169
C# Array Initialization Syntax 170
Implicitly Typed Local Arrays 171
Defining an Array of Objects 171
Working with Multidimensional Arrays 172
Arrays As Arguments or Return Values 174
The System.Array Base Class 174
Understanding the Enum Type 176
Controlling the Underlying Storage for an Enum 177
Declaring Enum Variables 178
The System.Enum Type 179
Dynamically Discovering an Enum’s Name/Value Pairs 180
Understanding the Structure Type 183
Creating Structure Variables 184
Understanding Value Types and Reference Types 186
Value Types, References Types, and the Assignment Operator 187
Value Types Containing Reference Types 189
Passing Reference Types by Value 190
Passing Reference Types by Reference 192
Final Details Regarding Value Types and Reference Types 193
Understanding C# Nullable Types 194
Working with Nullable Types 195
The ?? Operator 196
Summary 197
CHAPTER 5 Defining Encapsulated Class Types
198
Introducing the C# Class Type 198
Allocating Objects with the new Keyword 201
Understanding Constructors 201
The Role of the Default Constructor 202
Defining Custom Constructors 203
The Default Constructor Revisited 204
The Role of the this Keyword 205
Chaining Constructor Calls Using this 207
Observing Constructor Flow 209
Revisiting Optional Arguments 211
Understanding the static Keyword 212
Defining Static Methods 212
Defining Static Field Data 213
Defining Static Constructors 216
Defining Static Classes 218
Defining the Pillars of OOP 219
The Role of Encapsulation 220
The Role of Inheritance 220
The Role of Polymorphism 222
C# Access Modifiers 223
The Default Access Modifiers 224
Access Modifiers and Nested Types 225
The First Pillar: C#’s Encapsulation Services 225
Encapsulation Using Traditional Accessors and Mutators 226
Encapsulation Using .NET Properties 229
Using Properties within a Class Definition 231
Internal Representation of Properties 233
Controlling Visibility Levels of Property Get/Set Statements 235
Read-Only and Write-Only Properties 235
Static Properties 236
Understanding Automatic Properties 237
Interacting with Automatic Properties 239
Regarding Automatic Properties and Default Values 239
Understanding Object Initializer Syntax 241
Calling Custom Constructors with Initialization Syntax 243
Initializing Inner Types 244
Working with Constant Field Data 245
Understanding Read-Only Fields 246
Static Read-Only Fields 247
Understanding Partial Types 248
Summary 249
CHAPTER 6 Understanding Inheritance and Polymorphism
250
The Basic Mechanics of Inheritance 250
Specifying the Parent Class of an Existing Class 251
Regarding Multiple Base Classes 253
The sealed Keyword 253
Revising Visual Studio Class Diagrams 255
The Second Pillar of OOP: The Details of Inheritance 257
Controlling Base Class Creation with the base Keyword 259
Keeping Family Secrets: The protected Keyword 261
Adding a Sealed Class 262
Programming for Containment/Delegation 263
Understanding Nested Type Definitions 264
The Third Pillar of OOP: C#’s Polymorphic Support 266
The virtual and override Keywords 267
Overriding Virtual Members Using Visual Studio 2010 269
Sealing Virtual Members 270
Understanding Abstract Classes 271
Understanding the Polymorphic Interface 272
Understanding Member Shadowing 276
Understanding Base Class/Derived Class Casting Rules 278
The C# as Keyword 280
The C# is Keyword 281
The Master Parent Class: System.Object 281
Overriding System.Object.ToString() 285
Overriding System.Object.Equals() 285
Overriding System.Object.GetHashCode() 286
Testing Your Modified Person Class 287
The Static Members of System.Object 288
Summary 289
CHAPTER 7 Understanding Structured Exception Handling
290
Ode to Errors, Bugs, and Exceptions 290
The Role of .NET Exception Handling 291
The Atoms of .NET Exception Handling 292
The System.Exception Base Class 292
The Simplest Possible Example 294
Throwing a General Exception 296
Catching Exceptions 297
Configuring the State of an Exception 298
The TargetSite Property 299
The StackTrace Property 299
The HelpLink Property 300
The Data Property 301
System-Level Exceptions (System.SystemException) 303
Application-Level Exceptions (System.ApplicationException) 304
Building Custom Exceptions, Take One 304
Building Custom Exceptions, Take Two 306
Building Custom Exceptions, Take Three 307
Processing Multiple Exceptions 308
General catch Statements 310
Rethrowing Exceptions 311
Inner Exceptions 312
The Finally Block 313
Who Is Throwing What? 313
The Result of Unhandled Exceptions 314
Debugging Unhandled Exceptions Using Visual Studio 315
A Brief Word Regarding Corrupted State Exceptions (CSE) 316
Summary 318
CHAPTER 8 Understanding Object Lifetime
319
Classes, Objects, and References 319
The Basics of Object Lifetime 321
The CIL of new 322
Setting Object References to null 323
The Role of Application Roots 324
Understanding Object Generations 326
Concurrent Garbage Collection under .NET 1.0 - 3.5 327
Background Garbage Collection under .NET 4.0 327
The System.GC Type 328
Forcing a Garbage Collection 329
Building Finalizable Objects 332
Overriding System.Object.Finalize() 333
Detailing the Finalization Process 335
Building Disposable Objects 335
Reusing the C# using Keyword 338
Building Finalizable and Disposable Types 339
A Formalized Disposal Pattern 340
Understanding Lazy Object Instantiation 343
Customizing the Creation of the Lazy Data 345
Summary 346
PART 3 Advanced C# Programming Constructs
348
CHAPTER 9 Working with Interfaces
349
Understanding Interface Types 349
Interface Types vs. Abstract Base Classes 350
Defining Custom Interfaces 353
Implementing an Interface 355
Invoking Interface Members at the Object Level 357
Obtaining Interface References: The as Keyword 358
Obtaining Interface References: The is Keyword 358
Interfaces As Parameters 359
Interfaces As Return Values 361
Arrays of Interface Types 362
Implementing Interfaces Using Visual Studio 2010 363
Resolving Name Clashes via Explicit Interface Implementation
364
Designing Interface Hierarchies 367
Multiple Inheritance with Interface Types 369
Building Enumerable Types (IEnumerable and IEnumerator) 371
Building Iterator Methods with the yield Keyword 374
Building a Named Iterator 375
Internal Representation of an Iterator Method 376
Building Cloneable Objects (ICloneable) 377
A More Elaborate Cloning Example 379
Building Comparable Objects (IComparable) 382
Specifying Multiple Sort Orders (IComparer) 385
Custom Properties, Custom Sort Types 386
Summary 387
CHAPTER 10 Understanding Generics
388
The Issues with Non-Generic Collections 388
The Issue of Performance 390
The Issue of Type Safety 394
The Role of Generic Type Parameters 398
Specifying Type Parameters for Generic Classes / Structures 399
Specifying Type Parameters for Generic Members 401
Specifying Type Parameters for Generic Interfaces 401
The System.Collections.Generic Namespace 403
Understanding Collection Initialization Syntax 405
Working with the List< T>
Working with the Stack< T>
Working with the Queue< T>
Working with the SortedSet< T>
Creating Custom Generic Methods 412
Inference of Type Parameters 414
Creating Custom Generic Structures and Classes 415
The default Keyword in Generic Code 417
Generic Base Classes 418
Constraining Type Parameters 419
Examples Using the where Keyword 420
The Lack of Operator Constraints 421
Summary 422
CHAPTER 11 Delegates, Events, and Lambdas
423
Understanding the .NET Delegate Type 423
Defining a Delegate Type in C# 424
The System.MulticastDelegate and System.Delegate Base Classes
426
The Simplest Possible Delegate Example 428
Investigating a Delegate Object 430
Sending Object State Notifications using Delegates 431
Enabling Multicasting 434
Removing Targets from a Delegate’s Invocation List 436
Method Group Conversion Syntax 437
Understanding Delegate Covariance 439
Understanding Generic Delegates 441
Simulating Generic Delegates Without Generics 443
Understanding C# Events 444
The C# event Keyword 445
Events under the Hood 447
Listening to Incoming Events 448
Simplifying Event Registration Using Visual Studio 2010 449
Creating Custom Event Arguments 450
The Generic EventHandler< T>
Understanding C# Anonymous Methods 453
Accessing Local Variables 455
Understanding Lambda Expressions 456
Dissecting a Lambda Expression 459
Processing Arguments Within Multiple Statements 459
Lambda Expressions with Multiple (or Zero) Parameters 461
Retrofitting the CarEvents Example Using Lambda Expressions 462
Summary 463
CHAPTER 12 Advanced C# Language Features
464
Understanding Indexer Methods 464
Indexing Data Using String Values 466
Overloading Indexer Methods 468
Indexers with Multiple Dimensions 468
Indexer Definitions on Interface Types 469
Understanding Operator Overloading 469
Overloading Binary Operators 470
And What of the += and –+ Operators? 473
Overloading Unary Operators 473
Overloading Equality Operators 474
Overloading Comparison Operators 475
The Internal Representation of Overloaded Operators 476
Final Thoughts Regarding Operator Overloading 478
Understanding Custom Type Conversions 479
Recall: Numerical Conversions 479
Recall: Conversions Among Related Class Types 479
Creating Custom Conversion Routines 480
Additional Explicit Conversions for the Square Type 483
Defining Implicit Conversion Routines 483
The Internal Representation of Custom Conversion Routines 485
Understanding Extension Methods 485
Defining Extension Methods 486
Invoking Extension Methods on an Instance Level 488
Invoking Extension Methods Statically 489
The Scope of an Extension Method 489
Importing Types That Define Extension Methods 490
The IntelliSense of Extension Methods 491
Building and Using Extension Libraries 492
Extending Interface Types via Extension Methods 494
Understanding Partial Methods 495
A First Look at Partial Methods 496
Uses of Partial Methods 497
Understanding Anonymous Types 498
The Internal Representation of Anonymous Types 499
The Implementation of ToString() and GetHashCode() 501
The Semantics of Equality for Anonymous Types 501
Anonymous Types Containing Anonymous Types 503
Working with Pointer Types 504
The unsafe Keyword 506
Working with the * and & Operators
An Unsafe (and Safe) Swap Function 508
Field Access via Pointers (the -> Operator)
The stackalloc Keyword 510
Pinning a Type via the fixed Keyword 510
The sizeof Keyword 511
Summary 512
CHAPTER 13 LINQ to Objects
513
LINQ Specific Programming Constructs 513
Implicit Typing of Local Variables 514
Object and Collection Initialization Syntax 515
Lambda Expressions 515
Extension Methods 516
Anonymous Types 517
Understanding the Role of LINQ 517
LINQ Expressions Are Strongly Typed 519
The Core LINQ Assemblies 519
Applying LINQ Queries to Primitive Arrays 520
Once Again, Without LINQ 521
Reflecting Over a LINQ Result Set 522
LINQ and Implicitly Typed Local Variables 522
LINQ and Extension Methods 524
The Role of Deferred Execution 525
The Role of Immediate Execution 526
Returning the Result of a LINQ Query 527
Returning LINQ Results via Immediate Execution 529
Applying LINQ Queries to Collection Objects 529
Accessing Contained Subobjects 530
Applying LINQ Queries to Nongeneric Collections 531
Filtering Data Using OfType< T>
Investigating the C# LINQ Query Operators 532
Basic Selection Syntax 534
Obtaining Subsets of Data 535
Projecting New Data Types 536
Obtaining Counts Using Enumerable 537
Reversing Result Sets 538
Sorting Expressions 538
LINQ As a Better Venn Diagramming Tool 539
Removing Duplicates 540
LINQ Aggregation Operations 540
The Internal Representation of LINQ Query Statements 541
Building Query Expressions with Query Operators (Revisited) 542
Building Query Expressions Using the Enumerable Type and Lambda Expressions
543
Building Query Expressions Using the Enumerable Type and Anonymous Methods
544
Building Query Expressions Using the Enumerable Type and Raw Delegates
545
Summary 546
PART 4 Programming with .NET Assemblies
547
CHAPTER 14 Configuring .NET Assemblies
548
Defining Custom Namespaces 548
Resolving Name Clashes with Fully Qualified Names 550
Resolving Name Clashes with Aliases 551
Creating Nested Namespaces 553
The Default Namespace of Visual Studio 2010 554
The Role of .NET Assemblies 555
Assemblies Promote Code Reuse 555
Assemblies Establish a Type Boundary 555
Assemblies Are Versionable Units 555
Assemblies Are Self-Describing 556
Assemblies Are Configurable 556
Understanding the Format of a .NET Assembly 556
The Windows File Header 557
The CLR File Header 558
CIL Code, Type Metadata, and the Assembly Manifest 559
Optional Assembly Resources 559
Single-File and Multifile Assemblies 559
Building and Consuming a Single-File Assembly 561
Exploring the Manifest 564
Exploring the CIL 567
Exploring the Type Metadata 567
Building a C# Client Application 568
Building a Visual Basic Client Application 570
Cross-Language Inheritance in Action 572
Building and Consuming a Multifile Assembly 573
Exploring the ufo.netmodule File 574
Exploring the airvehicles.dll File 574
Consuming a Multifile Assembly 575
Understanding Private Assemblies 576
The Identity of a Private Assembly 576
Understanding the Probing Process 576
Configuring Private Assemblies 577
Configuration Files and Visual Studio 2010 579
Understanding Shared Assemblies 581
Understanding Strong Names 583
Generating Strong Names at the Command Line 584
Generating Strong Names using Visual Studio 2010 586
Installing Strongly Named Assemblies to the GAC 588
Viewing the .NET 4.0 GAC using Windows Explorer 589
Consuming a Shared Assembly 590
Exploring the Manifest of SharedCarLibClient 592
Configuring Shared Assemblies 592
Freezing the Current Shared Assembly 593
Building Shared Assembly Version 2.0.0.0 593
Dynamically Redirecting to Specific Versions of a Shared Assembly 596
Understanding Publisher Policy Assemblies 597
Disabling Publisher Policy 598
Understanding the < codeBase>
The System.Configuration Namespace 600
Summary 602
CHAPTER 15 Type Reflection, Late Binding, and Attribute-Based Programming
603
The Necessity of Type Metadata 603
Viewing (Partial) Metadata for the EngineState Enumeration 604
Viewing (Partial) Metadata for the Car Type 605
Examining a TypeRef 607
Documenting the Defining Assembly 607
Documenting Referenced Assemblies 607
Documenting String Literals 608
Understanding Reflection 608
The System.Type Class 609
Obtaining a Type Reference Using System.Object.GetType() 610
Obtaining a Type Reference Using typeof() 611
Obtaining a Type Reference Using System.Type.GetType() 611
Building a Custom Metadata Viewer 612
Reflecting on Methods 612
Reflecting on Fields and Properties 613
Reflecting on Implemented Interfaces 613
Displaying Various Odds and Ends 614
Implementing Main() 614
Reflecting on Generic Types 616
Reflecting on Method Parameters and Return Values 616
Dynamically Loading Assemblies 618
Reflecting on Shared Assemblies 620
Understanding Late Binding 622
The System.Activator Class 623
Invoking Methods with No Parameters 624
Invoking Methods with Parameters 625
Understanding the Role of .NET Attributes 626
Attribute Consumers 627
Applying Attributes in C# 628
C# Attribute Shorthand Notation 629
Specifying Constructor Parameters for Attributes 630
The Obsolete Attribute in Action 630
Building Custom Attributes 631
Applying Custom Attributes 632
Named Property Syntax 632
Restricting Attribute Usage 633
Assembly-Level (and Module-Level) Attributes 634
The Visual Studio 2010 AssemblyInfo.cs File 635
Reflecting on Attributes Using Early Binding 636
Reflecting on Attributes Using Late Binding 637
Putting Reflection, Late Binding, and Custom Attributes in Perspective
639
Building an Extendable Application 640
Building CommonSnappableTypes.dll 641
Building the C# Snap-In 641
Building the Visual Basic Snap-In 642
Building an Extendable Windows Forms Application 643
Summary 646
CHAPTER 16 Processes, AppDomains, and Object Contexts
647
The Role of a Windows Process 647
The Role of Threads 648
Interacting with Processes Under the .NET Platform 649
Enumerating Running Processes 652
Investigating a Specific Process 653
Investigating a Process’s Thread Set 653
Investigating a Process’s Module Set 656
Starting and Stopping Processes Programmatically 657
Controlling Process Startup using the ProcessStartInfo Class 658
Understanding .NET Application Domains 659
The System.AppDomain Class 660
Interacting with the Default Application Domain 662
Enumerating Loaded Assemblies 663
Receiving Assembly Load Notifications 665
Creating New Application Domains 665
Loading Assemblies into Custom Application Domains 667
Programmatically Unloading AppDomains 668
Understanding Object Context Boundaries 670
Context-Agile and Context-Bound Types 671
Defining a Context-Bound Object 671
Inspecting an Object’s Context 672
Summarizing Processes, AppDomains, and Context 674
Summary 674
CHAPTER 17 Understanding CIL and the Role of Dynamic Assemblies
675
Reasons for Learning the Grammar of CIL 675
Examining CIL Directives, Attributes, and Opcodes 676
The Role of CIL Directives 677
The Role of CIL Attributes 677
The Role of CIL Opcodes 677
The CIL Opcode/CIL Mnemonic Distinction 677
Pushing and Popping: The Stack-Based Nature of CIL 678
Understanding Round-Trip Engineering 680
The Role of CIL Code Labels 683
Interacting with CIL: Modifying an *.il File 684
Compiling CIL Code Using ilasm.exe 685
Authoring CIL Code Using SharpDevelop 687
The Role of peverify.exe 688
Understanding CIL Directives and Attributes 688
Specifying Externally Referenced Assemblies in CIL 688
Defining the Current Assembly in CIL 689
Defining Namespaces in CIL 690
Defining Class Types in CIL 690
Defining and Implementing Interfaces in CIL 692
Defining Structures in CIL 692
Defining Enums in CIL 693
Defining Generics in CIL 693
Compiling the CILTypes.il file 694
.NET Base Class Library, C#, and CIL Data Type Mappings 695
Defining Type Members in CIL 696
Defining Field Data in CIL 696
Defining Type Constructors in CIL 697
Defining Properties in CIL 698
Defining Member Parameters 698
Examining CIL Opcodes 699
The .maxstack Directive 702
Declaring Local Variables in CIL 702
Mapping Parameters to Local Variables in CIL 703
The Hidden this Reference 704
Representing Iteration Constructs in CIL 704
Building a .NET Assembly with CIL 705
Building CILCars.dll 705
Building CILCarClient.exe 708
Understanding Dynamic Assemblies 710
Exploring the System.Reflection.Emit Namespace 711
The Role of the System.Reflection.Emit.ILGenerator 712
Emitting a Dynamic Assembly 713
Emitting the Assembly and Module Set 715
The Role of the ModuleBuilder Type 716
Emitting the HelloClass Type and the String Member Variable 717
Emitting the Constructors 718
Emitting the SayHello() Method 719
Using the Dynamically Generated Assembly 719
Summary 720
CHAPTER 18 Dynamic Types and the Dynamic Language Runtime
722
The Role of the C# dynamic Keyword 722
Calling Members on Dynamically Declared Data 724
The Role of the Microsoft.CSharp.dll Assembly 726
The Scope of the dynamic keyword 727
Limitations of the dynamic Keyword 727
Practical Uses of the dynamic Keyword 728
The Role of the Dynamic Language Runtime (DLR) 728
The Role of Expression Trees 729
The Role of the System.Dynamic Namespace 730
Dynamic Runtime Lookup of Expression Trees 730
Simplifying Late Bound Calls Using Dynamic Types 731
Leveraging the dynamic Keyword to Pass Arguments 732
Simplifying COM Interoperability using Dynamic Data 735
The Role of Primary Interop Assemblies (PIAs) 736
Embedding Interop Metadata 737
Common COM Interop Pain Points 738
COM Interop using C# 4.0 Language Features 739
COM interop without C# 4.0 Language Features 743
Summary 744
PART 5 Introducing the .NET Base Class Libraries
746
CHAPTER 19 Multithreaded and Parallel Programming
747
The Process/AppDomain/Context/Thread Relationship 747
The Problem of Concurrency 748
The Role of Thread Synchronization 749
A Brief Review of the .NET Delegate 749
The Asynchronous Nature of Delegates 751
The BeginInvoke() and EndInvoke() Methods 752
The System.IAsyncResult Interface 752
Invoking a Method Asynchronously 753
Synchronizing the Calling Thread 754
The Role of the AsyncCallback Delegate 756
The Role of the AsyncResult Class 758
Passing and Receiving Custom State Data 758
The System.Threading Namespace 759
The System.Threading.Thread Class 761
Obtaining Statistics About the Current Thread 762
The Name Property 763
The Priority Property 764
Programmatically Creating Secondary Threads 764
Working with the ThreadStart Delegate 765
Working with the ParameterizedThreadStart Delegate 767
The AutoResetEvent Class 768
Foreground Threads and Background Threads 769
The Issue of Concurrency 770
Synchronization Using the C# lock Keyword 773
Synchronization Using the System.Threading.Monitor Type 775
Synchronization Using the System.Threading.Interlocked Type 776
Synchronization Using the [Synchronization] Attribute 777
Programming with Timer Callbacks 778
Understanding the CLR ThreadPool 780
Parallel Programming under the .NET Platform 781
The Task Parallel Library API 782
The Role of the Parallel Class 783
Understanding Data Parallelism 783
The Task Class 785
Handling Cancelation Request 786
Understanding Task Parallelism 788
Parallel LINQ Queries (PLINQ) 791
Opting in to a PLINQ Query 792
Canceling a PLINQ Query 792
Summary 794
CHAPTER 20 File I/O and Object Serialization
795
Exploring the System.IO Namespace 795
The Directory(Info) and File(Info) Types 797
The Abstract FileSystemInfo Base Class 797
Working with the DirectoryInfo Type 798
Enumerating Files with the DirectoryInfo Type 800
Creating Subdirectories with the DirectoryInfo Type 801
Working with the Directory Type 802
Working with the DriveInfo Class Type 803
Working with the FileInfo Class 805
The FileInfo.Create() Method 806
The FileInfo.Open() Method 806
The FileInfo.OpenRead() and FileInfo.OpenWrite() Methods 808
The FileInfo.OpenText() Method 809
The FileInfo.CreateText() and FileInfo.AppendText() Methods 809
Working with the File Type 809
Additional File-centric Members 810
The Abstract Stream Class 812
Working with FileStreams 813
Working with StreamWriters and StreamReaders 814
Writing to a Text File 815
Reading from a Text File 816
Directly Creating StreamWriter/StreamReader Types 817
Working with StringWriters and StringReaders 818
Working with BinaryWriters and BinaryReaders 819
Watching Files Programmatically 821
Understanding Object Serialization 824
The Role of Object Graphs 825
Configuring Objects for Serialization 826
Defining Serializable Types 827
Public Fields, Private Fields, and Public Properties 827
Choosing a Serialization Formatter 828
The IFormatter and IRemotingFormatter Interfaces 829
Type Fidelity Among the Formatters 830
Serializing Objects Using the BinaryFormatter 831
Deserializing Objects Using the BinaryFormatter 832
Serializing Objects Using the SoapFormatter 833
Serializing Objects Using the XmlSerializer 834
Controlling the Generated XML Data 835
Serializing Collections of Objects 836
Customizing the Soap/Binary Serialization Process 838
A Deeper Look at Object Serialization 839
Customizing Serialization Using ISerializable 840
Customizing Serialization Using Attributes 843
Summary 844
CHAPTER 21 ADO.NET Part I: The Connected Layer
845
A High-Level Definition of ADO.NET 845
The Three Faces of ADO.NET 846
Understanding ADO.NET Data Providers 847
The Microsoft-Supplied ADO.NET Data Providers 849
A Word Regarding System.Data.OracleClient.dll 850
Obtaining Third-Party ADO.NET Data Providers 851
Additional ADO.NET Namespaces 851
The Types of the System.Data Namespace 852
The Role of the IDbConnection Interface 853
The Role of the IDbTransaction Interface 854
The Role of the IDbCommand Interface 854
The Role of the IDbDataParameter and IDataParameter Interfaces 854
The Role of the IDbDataAdapter and IDataAdapter Interfaces 855
The Role of the IDataReader and IDataRecord Interfaces 856
Abstracting Data Providers Using Interfaces 857
Increasing Flexibility Using Application Configuration Files 859
Creating the AutoLot Database 860
Creating the Inventory Table 860
Authoring the GetPetName() Stored Procedure 863
Creating the Customers and Orders Tables 864
Visually Creating Table Relationships 866
The ADO.NET Data Provider Factory Model 867
A Complete Data Provider Factory Example 868
A Potential Drawback with the Provide Factory Model 871
The < connectionStrings>
Understanding the Connected Layer of ADO.NET 873
Working with Connection Objects 874
Working with ConnectionStringBuilder Objects 876
Working with Command Objects 878
Working with Data Readers 879
Obtaining Multiple Result Sets Using a Data Reader 881
Building a Reusable Data Access Library 881
Adding the Connection Logic 883
Adding the Insertion Logic 883
Adding the Deletion Logic 885
Adding the Update Logic 885
Adding the Selection Logic 886
Working with Parameterized Command Objects 887
Specifying Parameters Using the DbParameter Type 887
Executing a Stored Procedure 889
Creating a Console UI–Based Front End 891
Implementing the Main() Method 892
Implementing the ShowInstructions() Method 893
Implementing the ListInventory() Method 894
Implementing the DeleteCar() Method 895
Implementing the InsertNewCar() Method 895
Implementing the UpdateCarPetName() Method 896
Implementing LookUpPetName() 896
Understanding Database Transactions 897
Key Members of an ADO.NET Transaction Object 898
Adding a CreditRisks Table to the AutoLot Database 899
Adding a Transaction Method to InventoryDAL 900
Testing Your Database Transaction 902
Summary 903
CHAPTER 22 ADO.NET Part II: The Disconnected Layer
904
Understanding the Disconnected Layer of ADO.NET 904
Understanding the Role of the DataSet 905
Key Properties of the DataSet 906
Key Methods of the DataSet 907
Building a DataSet 908
Working with DataColumns 908
Building a DataColumn 910
Enabling Autoincrementing Fields 911
Adding DataColumn Objects to a DataTable 911
Working with DataRows 912
Understanding the RowState Property 913
Understanding the DataRowVersion Property 915
Working with DataTables 916
Inserting DataTables into DataSets 917
Obtaining Data in a DataSet 917
Processing DataTable Data Using DataTableReader Objects 918
Serializing DataTable/DataSet Objects As XML 920
Serializing DataTable/DataSet Objects in a Binary Format 921
Binding DataTable Objects to Windows Forms GUIs 922
Hydrating a DataTable from a Generic List< T>
Deleting Rows from a DataTable 926
Selecting Rows Based on Filter Criteria 927
Updating Rows Within a DataTable 930
Working with the DataView Type 931
Working with Data Adapters 932
A Simple Data Adapter Example 933
Mapping Database Names to Friendly Names 935
Adding Disconnection Functionality to AutoLotDAL.dll 936
Defining the Initial Class Type 936
Configuring the Data Adapter Using the SqlCommandBuilder 937
Implementing GetAllInventory() 938
Implementing UpdateInventory() 938
Setting Your Version Number 938
Testing the Disconnected Functionality 939
Multitabled DataSet Objects and Data Relationships 940
Prepping the Data Adapters 941
Building the Table Relationships 943
Updating the Database Tables 943
Navigating Between Related Tables 944
The Windows Forms Database Designer Tools 946
Visually Designing the DataGridView 946
The Generated app.config File 951
Examining the Strongly Typed DataSet 951
Examining the Strongly Typed DataTable 953
Examining the Strongly Typed DataRow 954
Examining the Strongly Typed Data Adapter 955
Completing the Windows Forms Application 956
Isolating Strongly Typed Database Code into a Class Library 957
Viewing the Generated Code 958
Selecting Data with the Generated Code 959
Inserting Data with the Generated Code 960
Deleting Data with the Generated Code 961
Invoking a Stored Procedure using the Generated Code 962
Programming with LINQ to DataSet 962
The Role of the DataSet Extensions Library 964
Obtaining a LINQ-Compatible DataTable 965
The Role of the DataRowExtensions.Field< T>
Hydrating New DataTables from LINQ Queries 967
Summary 968
CHAPTER 23 ADO.NET Part III: The Entity Framework
970
Understanding the Role of Entity Framework 970
The Role of Entities 972
The Building Blocks of the Entity Framework 974
The Role of Object Services 975
The Role of the Entity Client 975
The Role of the *.edmx File (and Friends) 977
The Role of the ObjectContext and ObjectSet< T>
All Together Now! 979
Building and Analyzing your First EDM 980
Generating the *.edmx File 980
Reshaping the Entity Data 984
Viewing the Mappings 986
Viewing the Generated *.edmx File Data 987
Viewing the Generated Source Code 989
Enhancing the Generated Source Code 991
Programming Against the Conceptual Model 992
Deleting a Record 993
Updating a Record 994
Querying with LINQ to Entities 994
Querying with Entity SQL 996
Working with the Entity Client Data Reader Object 997
AutoLotDAL Version 4.0, Now with Entities 998
Mapping the Stored Procedure 999
The Role of Navigation Properties 1001
Using Navigation Properties within LINQ to Entity Queries 1003
Invoking a Stored Procedure 1004
Data Binding Entities to Windows Forms GUIs 1005
Adding the Data Binding Code 1008
Summary 1010
CHAPTER 24 Introducing LINQ to XML
1011
A Tale of Two XML APIs 1011
LINQ to XML As a Better DOM 1013
VB Literal Syntax As a Better LINQ to XML 1014
Members of the System.Xml.Linq Namespace 1015
The LINQ to XML Axis Methods 1018
The Oddness of XName (and XNamespace) 1019
Working with XElement and XDocument 1020
Generating Documents from Arrays and Containers 1022
Loading and Parsing XML Content 1024
Manipulating an in Memory XML Document 1024
Building the UI of the LINQ to XML App 1025
Import the Inventory.xml File 1025
Defining a LINQ to XML Helper Class 1026
Rigging up the UI to Your Helper Class 1027
Summary 1029
CHAPTER 25 Introducing Windows Communication Foundation
1030
A Potpourri of Distributed Computing APIs 1030
The Role of DCOM 1031
The Role of COM+/Enterprise Services 1032
The Role of MSMQ 1032
The Role of .NET Remoting 1033
The Role of XML Web Services 1033
A .NET Web Service Example 1034
Web Service Standards 1036
Named Pipes, Sockets, and P2P 1036
The Role of WCF 1036
An Overview of WCF Features 1037
An Overview of Service-Oriented Architecture 1038
Tenet 1: Boundaries Are Explicit 1038
Tenet 2: Services Are Autonomous 1038
Tenet 3: Services Communicate via Contract, Not Implementation 1038
Tenet 4: Service Compatibility Is Based on Policy 1038
WCF: The Bottom Line 1039
Investigating the Core WCF Assemblies 1039
The Visual Studio WCF Project Templates 1040
The WCF Service Website Project Template 1042
The Basic Composition of a WCF Application 1042
The ABCs of WCF 1044
Understanding WCF Contracts 1044
Understanding WCF Bindings 1045
HTTP-Based Bindings 1046
TCP-Based Bindings 1047
MSMQ-Based Bindings 1048
Understanding WCF Addresses 1048
Building a WCF Service 1049
The [ServiceContract] Attribute 1051
The [OperationContract] Attribute 1052
Service Types As Operational Contracts 1052
Hosting the WCF Service 1053
Establishing the ABCs Within an App.config File 1054
Coding Against the ServiceHost Type 1055
Specifying Base Addresses 1055
Details of the ServiceHost Type 1057
Details of the < system.serviceModel>
Enabling Metadata Exchange 1060
Building the WCF Client Application 1063
Generating Proxy Code Using svcutil.exe 1063
Generating Proxy Code Using Visual Studio 2010 1064
Configuring a TCP-Based Binding 1066
Simplifying Configuration Settings with WCF 4.0 1067
Default Endpoints in WCF 4.0 1068
Exposing a Single WCF Service Using Multiple Bindings 1069
Changing Settings for a WCF Binding 1070
The WCF 4.0 Default MEX Behavior Configuration 1071
Refreshing the Client Proxy and Selecting the Binding 1073
Using the WCF Service Library Project Template 1074
Building a Simple Math Service 1074
Testing the WCF Service with WcfTestClient.exe 1075
Altering Configuration Files Using SvcConfigEditor.exe 1076
Hosting the WCF Service within a Windows Service 1078
Specifying the ABCs in Code 1079
Enabling MEX 1081
Creating a Windows Service Installer 1081
Installing the Windows Service 1083
Invoking a Service Asynchronously from the Client 1084
Designing WCF Data Contracts 1087
Using the Web-Centric WCF Service Project Template 1088
Implementing the Service Contract 1090
The Role of the *.svc File 1091
Examining the Web.config File 1092
Testing the Service 1092
Summary 1093
CHAPTER 26 Introducing Windows Workflow Foundation 4.0
1094
Defining a Business Process 1095
The Role of WF 4.0 1095
Building a (Painfully) Simple Workflow 1096
Viewing the Underlying XAML 1098
The WF 4.0 Runtime 1100
Hosting a Workflow using WorkflowInvoker 1100
Passing Arguments to your Workflow using WorkflowInvoker 1101
Defining Arguments using the Workflow Designer 1101
Hosting a Workflow using WorkflowApplication 1103
Recap of your First Workflow 1105
Examining the Workflow 4.0 Activities 1105
Control Flow Activities 1106
Flowchart Activities 1106
Messaging Activities 1107
The Runtime and Primitives Activities 1108
The Transaction Activities 1108
The Collection and Error Handling Activities 1109
Building a Flowchart Workflow 1110
Connecting Activities in a Flowchart 1111
Working with the InvokeMethod Activity 1111
Defining Workflow Wide Variables 1112
Working with the FlowDecision Activity 1113
Working with the TerminateWorkflow Activity 1114
Building the “True” Condition 1115
Working with the ForEach< T>
Completing the Application 1117
Reflecting on What We Have Done 1118
Isolating Workflows into Dedicated Libraries 1120
Defining the Initial Project 1120
Importing Assemblies and Namespaces 1122
Defining the Workflow Arguments 1122
Defining Workflow Variables 1123
Working with the Assign Activity 1124
Working with the If and Switch Activities 1124
Building a Custom Code Activity 1126
Consuming the Workflow Library 1129
Retrieving the Workflow Output Argument 1130
Summary 1131
PART 6 Building Desktop User Interfaces with WPF
1132
CHAPTER 27 Introducing Windows Presentation Foundation and XAML
1133
The Motivation Behind WPF 1133
Unifying Diverse APIs 1134
Providing a Separation of Concerns via XAML 1135
Providing an Optimized Rendering Model 1136
Simplifying Complex UI Programming 1136
The Various Flavors of WPF 1137
Traditional Desktop Applications 1137
Navigation-Based WPF Applications 1140
XBAP Applications 1140
The WPF/Silverlight Relationship 1142
Investigating the WPF Assemblies 1142
The Role of the Application Class 1144
Constructing an Application Class 1145
Enumerating the Application.Windows collection 1146
The Role of the Window Class 1146
The Role of System.Windows.Controls.ContentControl 1147
The Role of System.Windows.Controls.Control 1148
The Role of System.Windows.FrameworkElement 1149
The Role of System.Windows.UIElement 1150
The Role of System.Windows.Media.Visual 1150
The Role of System.Windows.DependencyObject 1151
The Role of System.Windows.Threading.DispatcherObject 1151
Building a WPF Application without XAML 1151
Creating a Strongly Typed Window 1153
Creating a Simple User Interface 1154
Interacting with Application Level Data 1155
Handling the Closing of a Window Object 1157
Intercepting Mouse Events 1158
Intercepting Keyboard Events 1159
Building a WPF Application using Only XAML 1160
Defining MainWindow in XAML 1162
Defining the Application Object in XAML 1163
Processing the XAML Files using msbuild.exe 1164
Transforming Markup into a .NET Assembly 1166
Mapping the Window XAML Data to C# Code 1166
The Role of BAML 1167
Mapping the Application XAML Data to C# Code 1169
XAML-to-Assembly Process Summary 1169
Understanding The Syntax of WPF XAML 1170
Introducing Kaxaml 1170
XAML XML Namespaces and XAML "Keywords" 1172
Controlling Class and Member Variable Declarations 1175
XAML Elements, XAML Attributes and Type Converters 1176
Understanding XAML Property-Element Syntax 1177
Understanding XAML Attached Properties 1178
Understanding XAML Markup Extensions 1179
Building a WPF Application using Code-Behind Files 1181
Adding a Code File for the MainWindow Class 1181
Adding a Code File for the MyApp Class 1182
Processing the Code Files with msbuild.exe 1182
Building WPF Applications Using Visual Studio 2010 1183
The WPF Project Templates 1184
Exploring the WPF Designer Tools 1185
Designing the GUI of our Window 1189
Implementing the Loaded Event 1190
Implementing the Button’s Click Event 1191
Implementing the Closed Event 1193
Testing the Application 1193
Summary 1194
CHAPTER 28 Programming with WPF Controls
1195
A Survey of the Core WPF Controls 1195
Working with WPF Controls Using Visual Studio 2010 1197
The WPF Ink Controls 1198
The WPF Document Controls 1199
WPF Common Dialog Boxes 1199
The Details Are in the Documentation 1200
Controlling Content Layout Using Panels 1200
Positioning Content Within Canvas Panels 1202
Positioning Content Within WrapPanel Panels 1204
Positioning Content Within StackPanel Panels 1206
Positioning Content Within Grid Panels 1207
Grids with GridSplitter Types 1208
Positioning Content Within DockPanel Panels 1209
Enabling Scrolling for Panel Types 1210
Building a Window’s Frame Using Nested Panels 1211
Building the Menu System 1212
Building the ToolBar 1213
Building the StatusBar 1214
Finalizing the UI Design 1214
Implementing the MouseEnter/MouseLeave Event Handlers 1215
Implementing the Spell Checking Logic 1216
Understanding WPF Control Commands 1216
The Intrinsic Control Command Objects 1217
Connecting Commands to the Command Property 1218
Connecting Commands to Arbitrary Actions 1219
Working with the Open and Save Commands 1220
Building a WPF User Interface with Expression Blend 1223
Getting to know the Key Aspects of the Blend IDE 1223
Using the TabControl 1229
Building the Ink API Tab 1232
Designing the ToolBar 1233
The RadioButton Control 1236
The InkCanvas Control 1238
The ComboBox Control 1240
Saving, Loading, and Clearing InkCanvas Data 1242
Introducing the Documents API 1243
Block Elements and Inline Elements 1243
Document Layout Managers 1244
Building the Documents Tab 1244
Populating a FlowDocument using Blend 1246
Populating a FlowDocument Using Code 1247
Enabling Annotations and Sticky Notes 1248
Saving and Loading a Flow Document 1250
Introducing the WPF Data-Binding Model 1251
Building the Data Binding Tab 1252
Establishing Data Bindings using Blend 1252
The DataContext Property 1255
Data Conversion Using IValueConverter 1256
Establishing Data Bindings in Code 1257
Building the DataGrid Tab 1258
Summary 1260
CHAPTER 29 WPF Graphics Rendering Services
1261
Understanding WPF's Graphical Rendering Services 1261
WPF Graphical Rendering Options 1262
Rendering Graphical Data Using Shapes 1263
Adding Rectangles, Ellipses, and Lines to a Canvas 1265
Removing Rectangles, Ellipses, and Lines from a Canvas 1268
Working with Polylines and Polygons 1269
Working with Paths 1270
The Path "Modeling Mini Language" 1272
WPF Brushes and Pens 1273
Configuring Brushes Using Visual Studio 2010 1274
Configuring Brushes in Code 1276
Configuring Pens 1277
Applying Graphical Transformations 1278
A First Look at Transformations 1279
Transforming our Canvas Data 1280
Working with Shapes using Expression Blend 1282
Selecting a Shape to Render from the Tool Palette 1282
Converting Shapes to Paths 1283
Combining Shapes 1284
The Brush and Transformation Editors 1285
Rendering Graphical Data Using Drawings and Geometries 1287
Building a DrawingBrush using Geometries 1288
Painting with the DrawingBrush 1289
Containing Drawing Types in a DrawingImage 1290
Generating Complex Vector Graphics using Expression Design
1291
Exporting a Design Document to XAML 1291
Rendering Graphical Data Using the Visual Layer 1293
The Visual Base Class and Derived Child Classes 1293
A First Look at using the DrawingVisual Class 1294
Rendering Visual Data to a Custom Layout Manager 1296
Responding to Hit Test Operations 1298
Summary 1300
CHAPTER 30 WPF Resources, Animations, and Styles
1301
Understanding the WPF Resource System 1301
Working with Binary Resources 1301
Including Loose Resource Files in a Project 1302
Configuring the Loose Resources 1303
Programmatically Loading an Image 1304
Embedding Application Resources 1305
Working with Object (Logical) Resources 1308
The Role of the Resources Property 1308
Defining Window-Wide Resources 1308
The {StaticResource} Markup Extension 1310
Changing a Resource after Extraction 1311
The {DynamicResource} Markup Extension 1311
Application-Level Resources 1312
Defining Merged Resource Dictionaries 1314
Defining a Resource-Only Assembly 1316
Extracting Resources in Expression Blend 1317
Understanding WPF’s Animation Services 1319
The Role of the Animation Class Types 1320
The To, From, and By Properties 1321
The Role of the Timeline Base Class 1321
Authoring an Animation in C# Code 1322
Controlling the Pacing of an Animation 1323
Reversing and Looping an Animation 1324
Authoring Animations in XAML 1325
The Role of Storyboards 1326
The Role of Event Triggers 1326
Animation Using Discrete Key Frames 1327
Understanding the Role of WPF Styles 1328
Defining and Applying a Style 1329
Overriding Style Settings 1330
Automatically Applying a Style with TargetType 1330
Subclassing Existing Styles 1331
The Role of Unnamed Styles 1332
Defining Styles with Triggers 1333
Defining Styles with Multiple Triggers 1333
Animated Styles 1334
Assigning Styles Programmatically 1335
Generating Styles with Expression Blend 1336
Working with Default Visual Styles 1336
Summary 1340
CHAPTER 31 WPF Control Templates and User Controls 1341
Understanding the Role of Dependency Properties 1341
Examining an Existing Dependency Property 1343
Important Notes Regarding CLR Property Wrappers 1346
Building a Custom Dependency Property 1347
Adding a Data Validation Routine 1351
Responding to the Property Change 1351
Understanding Routed Events 1353
The Role of Routed Bubbling Events 1354
Continuing or Halting Bubbling 1355
The Role of Routed Tunneling Events 1355
Logical Trees, Visual Trees and Default Templates 1357
Programmatically Inspecting a Logical Tree 1358
Programmatically Inspecting a Visual Tree 1359
Programmatically Inspecting a Control’s Default Template 1360
Building a Custom Control Template with Visual Studio 2010 1364
Templates as Resources 1365
Incorporating Visual Cues using Triggers 1367
The Role of {TemplateBinding} Markup Extension 1368
The Role of ContentPresenter 1370
Incorporating Templates into Styles 1370
Building Custom UserControls with Blend 1372
Creating a UserControl Library Project 1372
Renaming the Initial UserControl 1373
Designing the SpinControl 1374
Adding the Initial C# Code 1375
Defining an Animation using Blend 1375
Programmatically Starting our Storyboard 1379
Creating the Jackpot Deluxe WPF Application 1380
Extracting a UserControl from a Drawing Geometry 1381
The Role of .NET 4.0 Visual States 1382
Defining Visual States for the StarButton Control 1383
Defining State Transition Timings 1384
Viewing the Generated XAML 1385
Changing Visual States in Code using the VisualStateManager Class 1386
Finalizing the Jackpot Deluxe Application 1387
Summary 1391
PART 7 Building Web Applications with ASP .NET
1392
CHAPTER 32 Building ASP.NET Web Pages
1393
The Role of HTTP 1393
The HTTP Request/Response Cycle 1394
HTTP Is a Stateless Protocol 1394
Understanding Web Applications and Web Servers 1394
The Role of IIS Virtual Directories 1395
The ASP.NET Development Web Server 1396
The Role of HTML 1396
HTML Document Structure 1397
The Role of an HTML Form 1398
The Visual Studio 2010 HTML Designer Tools 1398
Building an HTML Form 1400
The Role of Client-Side Scripting 1402
A Client-Side Scripting Example 1403
Posting Back to the Web Server 1404
Postbacks under ASP.NET 1405
The Feature Set of the ASP.NET API 1405
Major Features of ASP.NET 1.0-1.1 1406
Major Features of ASP.NET 2.0 1407
Major Features of ASP.NET 3.5 (and .NET 3.5 SP1) 1408
Major Features of ASP.NET 4.0 1408
Building a Single File ASP.NET Web Page 1409
Referencing AutoLotDAL.dll 1410
Designing the UI 1410
Adding the Data Access Logic 1411
The Role of ASP.NET Directives 1415
Analyzing the “Script” Block 1417
Analyzing the ASP.NET Control Declarations 1417
Compilation Cycle for Single-File Pages 1419
Building an ASP.NET Web Page using Code Files 1420
Referencing the AutoLotDAL.dll Assembly 1423
Updating the Code File 1423
Compilation Cycle for Multifile Pages 1424
Debugging and Tracing ASP.NET Pages 1424
ASP.NET Web Sites and ASP.NET Web Applications 1426
The ASP.NET Web Site Directory Structure 1427
Referencing Assemblies 1428
The Role of the App_Code Folder 1429
The Inheritance Chain of the Page Type 1430
Interacting with the Incoming HTTP Request 1431
Obtaining Brower Statistics 1433
Access to Incoming Form Data 1433
The IsPostBack Property 1434
Interacting with the Outgoing HTTP Response 1435
Emitting HTML Content 1436
Redirecting Users 1436
The Life Cycle of an ASP.NET Web Page 1437
The Role of the AutoEventWireup Attribute 1438
The Error Event 1439
The Role of the Web.config File 1441
The ASP.NET Website Administration Utility 1442
Summary 1442
CHAPTER 33 ASP.NET Web Controls, Master Pages and Themes
1443
Understanding the Nature of Web Controls 1443
Understanding Server-Side Event Handling 1444
The AutoPostBack Property 1445
The Control and WebControl Base Classes 1446
Enumerating Contained Controls 1446
Dynamically Adding and Removing Controls 1449
Interacting with Dynamically Created Controls 1450
Functionality of the WebControl Base Class 1451
Major Categories of ASP.NET Web Controls 1452
A Brief Word Regarding System.Web.UI.HtmlControls 1454
Web Control Documentation 1455
Building the ASP.NET Cars Web Site 1455
Working with ASP.NET Master Pages 1456
Working with the TreeView Control Site Navigation Logic 1459
Establishing Bread Crumbs with the SiteMapPath Type 1461
Working with the AdRotator 1461
Defining the Default Content Page 1462
Designing the Inventory Content Page 1464
Enabling Sorting and Paging 1467
Enabling In-Place Editing 1468
Designing the Build-a-Car Content Page 1469
The Role of the Validation Controls 1471
The RequiredFieldValidator 1473
The RegularExpressionValidator 1474
The RangeValidator 1474
The CompareValidator 1475
Creating Validation Summaries 1476
Defining Validation Groups 1477
Working with Themes 1479
Understanding *.skin Files 1480
Applying Sitewide Themes 1482
Applying Themes at the Page Level 1483
The SkinID Property 1483
Assigning Themes Programmatically 1483
Summary 1485
CHAPTER 34 ASP.NET State Management Techniques
1486
The Issue of State 1486
ASP.NET State Management Techniques 1489
Understanding the Role of ASP.NET View State 1489
Demonstrating View State 1490
Adding Custom View State Data 1491
The Role of the Global.asax File 1492
The Global Last-Chance Exception Event Handler 1494
The HttpApplication Base Class 1495
Understanding the Application/Session Distinction 1496
Maintaining Application-Level State Data 1497
Modifying Application Data 1499
Handling Web Application Shutdown 1501
Working with the Application Cache 1501
Fun with Data Caching 1502
Modifying the *.aspx File 1504
Maintaining Session Data 1506
Additional Members of HttpSessionState 1509
Understanding Cookies 1510
Creating Cookies 1511
Reading Incoming Cookie Data 1512
The Role of the < sessionState>
Storing Session Data in the ASP.NET Session State Server 1513
Storing Session Data in a Dedicated Database 1515
Understanding the ASP.NET Profile API 1515
The ASPNETDB.mdf Database 1516
Defining a User Profile Within Web.config 1517
Accessing Profile Data Programmatically 1518
Grouping Profile Data and Persisting Custom Objects 1520
Summary 1522
APPENDIX A Programming with Windows Forms
1523
The Windows Forms Namespaces 1524
Building a Simple Windows Forms Application 1525
Populating the Controls Collection 1527
The Role of System.EventArgs and System.EventHandler 1529
The Visual Studio Windows Forms Project Template 1530
The Visual Designer Surface 1531
Dissecting the Initial Form 1532
Dissecting the Program Class 1533
Visually Building a Menu System 1534
The Anatomy of a Form 1537
The Functionality of the Control Class 1538
The Functionality of the Form Class 1541
The Life Cycle of a Form Type 1543
Responding to Mouse and Keyboard Activity 1546
Determining Which Mouse Button Was Clicked 1547
Determining Which Key Was Pressed 1548
Designing Dialog Boxes 1550
The DialogResult Property 1551
Configuring the Tab Order 1552
The Tab Order Wizard 1552
Setting the Form’s Default Input Button 1553
Displaying Dialog Boxes 1554
Understanding Form Inheritance 1555
Rendering Graphical Data Using GDI+ 1557
The System.Drawing Namespace 1559
The Role of the Graphics Type 1560
Obtaining a Graphics Object with the Paint Event 1561
Invalidating the Form’s Client Area 1563
Building a Complete Windows Forms Application 1563
Building the Main Menu System 1564
Defining the ShapeData Type 1565
Defining the ShapePickerDialog Type 1565
Adding Infrastructure to the MainWindow Type 1567
Implementing the Tools Menu Functionality 1567
Capturing and Rendering the Graphical Output 1569
Implementing the Serialization Logic 1570
Summary 1572
APPENDIX B Platform-Independent .NET Development with Mono
1573
The Platform-Independent Nature of .NET 1573
The Role of the CLI 1574
The Mainstream CLI Distributions 1575
The Scope of Mono 1576
Obtaining and Installing Mono 1577
Examining Mono’s Directory Structure 1579
The Mono Development Languages 1581
Working with the C# Compiler 1581
Building Mono Applications using MonoDevelop 1581
Microsoft-Compatible Mono Development Tools 1582
Mono-Specific Development Tools 1583
Using monop 1584
Building .NET Applications with Mono 1584
Building a Mono Code Library 1584
Assigning CoreLibDumper.dll a Strong Name 1586
Viewing the Updated Manifest with monodis 1586
Installing Assemblies into the Mono GAC 1587
Building a Console Application in Mono 1588
Loading Your Client Application in the Mono Runtime 1589
Building a Windows Forms Client Program 1590
Executing Your Windows Forms Application Under Linux 1592
Who is Using Mono? 1593
Suggestions for Further Study 1593
Summary 1594
Index 1595
Erscheint lt. Verlag | 7.7.2010 |
---|---|
Zusatzinfo | 1752 p. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Software Entwicklung ► Objektorientierung |
Mathematik / Informatik ► Informatik ► Theorie / Studium | |
Mathematik / Informatik ► Informatik ► Web / Internet | |
Schlagworte | ADO.NET • Attribut • C# • CIL • Generics • LINQ • .NET • object • Polymorphism • programming • WINDOWS • Windows Communication Foundation • Windows Presentation Foundation • Windows Workflow Foundation • XML |
ISBN-10 | 1-4302-2550-5 / 1430225505 |
ISBN-13 | 978-1-4302-2550-8 / 9781430225508 |
Haben Sie eine Frage zum Produkt? |
![PDF](/img/icon_pdf_big.jpg)
Größe: 12,6 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschränkt geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.
Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich