Explore Visual Basic 2012 and .NET 4.5 with this fully updated resource
After a quick review of the of introductory topics of Visual Basic 2012 and .NET 4.5, this book moves quickly into advanced topics such as data access with ADO.NET, security, ASP.NET web programming with Visual Basic, Windows workflow, and threading. You’ll explore the essential Visual Basic 2012 functions you need, including .NET features such as LINQ, WCF, and more. Plus, you’ll examine exception handling and debugging, Visual Studio features, and deployment.
- Puts the new Async keyword and Iterators to work
- Explores new options and interfaces presented by Windows 8 development and Win RT
- Continues strong coverage of core language elements and tools and creating componentized applications
This updated version of Professional Visual Basic 2012 and .NET 4.5 retains its expert author team, including one of the best-known and respected Microsoft Visual Basic MVPs, Bill Sheldon, and Microsoft Regional Director “Software Legend” Billy Hollis.
表中的内容
INTRODUCTION xxxi
PART I: LANGUAGE CONSTRUCTS AND ENVIRONMENT
CHAPTER 1: VISUAL STUDIO 2012 3
Visual Studio 2012 4
Visual Basic Keywords and Syntax 5
Console Applications 10
Creating a Project from a Project Template 11
The Solution Explorer 14
Project Properties 15
Assembly Information Screen 16
Compiler Settings 18
Debug Properties 21
References 23
Resources 24
Settings 26
Other Project Property Tabs 27
Project Pro VB_VS2012 28
Enhancing a Sample Application 31
Customizing the Code 33
Building Applications 44
Running an Application in the Debugger 45
Reusing Your First Windows Form 52
Useful Features of Visual Studio 2012 52
The Task List 52
Server Explorer 53
Class Diagrams 54
Summary 56
CHAPTER 2: THE COMMON LANGUAGE RUNTIME 57
Framework Profi les and Platforms 58
Client and Full Framework Profi les 59
Framework for Metro 59
Silverlight, Windows Phone, and Others 60
.NET 4.5 Portable Class Library 60
Elements of a .NET Application 61
Types 61
Modules 62
Assemblies 63
Cross-Language Integration 65
The Common Type System 65
Metadata 66
The Reflection API 69
IL Disassembler 70
Memory Management 71
Traditional Garbage Collection 72
Faster Memory Allocation for Objects 77
Garbage Collector Optimizations 79
Namespaces 81
What Is a Namespace? 81
Namespaces and References 84
Common Namespaces 86
Importing and Aliasing Namespaces 86
Aliasing Namespaces 89
Referencing Namespaces in ASP.NET 89
Creating Your Own Namespaces 90
The My Keyword 93
My.Application 94
My.Computer 97
My.Resources 99
My.User 99
Extending the My Namespace 100
Summary 102
CHAPTER 3: OBJECTS AND VISUAL BASIC 103
Object-Oriented Terminology 105
Objects, Classes, and Instances 105
Composition of an Object 105
System.Object 108
Working With Visual Basic Types 109
Value and Reference Types 109
Primitive Types 112
Commands: Conditional 114
If Then 114
Comparison Operators 115
Select Case 117
Value Types (Structures) 117
Boolean 118
Integer Types 119
Unsigned Types 120
Decimal Types 121
Char and Byte 123
Date Time 124
Reference Types (Classes) 125
The Object Class 125
The String Class 126
The DBNull Class and Is DBNull Function 130
Parameter Passing 131
Param Array 132
Variable Scope 133
Working with Objects 134
Objects Declaration and Instantiation 134
Object References 135
Early Binding versus Late Binding 136
Data Type Conversions 137
Performing Explicit Conversions 138
Creating Classes 143
Basic Classes 143
Handling Events 152
Handling Multiple Events 153
The With Events Keyword 154
Raising Events 154
Declaring and Raising Custom Events 155
Receiving Events with With Events 156
Receiving Events with Add Handler 158
Constructor Methods 160
Object-Oriented Concepts 161
Overloading Methods 161
Overloading Constructor Methods 164
Shared Methods, Variables, and Events 165
Operator Overloading 169
Delegates 172
Summary 176
CHAPTER 4: CUSTOM OBJECTS 179
Inheritance 180
When to Use Inheritance 181
Implementing Inheritance 183
Interacting with the Base Class, Yourself, and Your Class 202
Constructors 206
Object Scope 209
Events and Inheritance 211
Shared Methods 213
Creating an Abstract Base Class 213
Multiple Interfaces 216
Object Interfaces 216
Abstract Interfaces 217
Abstraction 225
Encapsulation 228
Polymorphism 228
Method Signatures 228
Implementing Polymorphism 229
Summary 235
CHAPTER 5: ADVANCED LANGUAGE CONSTRUCTS 237
Preparing the Sample Application 238
Lambda Expressions 240
Creating a Lambda Expression Subroutine 241
Creating a Lambda Expression Function 242
Using Lambda Expressions 243
Handling Events with Lambdas 244
LINQ with Lambdas 245
Async and Await 247
The Core Concept 248
Using Async and Await 252
Iterators 256
The Core Concept 256
Using Iterators 259
Summary 261
CHAPTER 6: EXCEPTION HANDLING AND DEBUGGING 263
System.Exception 264
Handling Exceptions 265
Try, Catch, and Finally 265
The Throw Keyword 267
The Exit Try Statement 268
Using Exception Properties 269
Logging Errors 273
The Event Log 273
Using the Trace and Debug Objects 275
Summary 278
PART II: BUSINESS OBJECTS AND DATA ACCESS
CHAPTER 7: ARRAYS, COLLECTIONS, AND GENERICS 281
Arrays 282
Multidimensional Arrays 284
The UBound Function 284
The Re Dim Statement 285
The Preserve Keyword 286
Collections 286
Iterative Statements 288
Boxing 291
Generics 292
Using Generics 293
Nullable Types 294
Generic Types 295
Generic Methods 298
Creating Generics 300
Generic Types 300
Generic Methods 307
Constraints 308
Generics and Late Binding 311
Covariance and Contravariance 312
Summary 314
CHAPTER 8: USING XML WITH VISUAL BASIC 315
An Introduction to XML 316
XML Serialization 318
Serializing 318
Deserializing 320
Source Code Style Attributes 322
System.Xml Document Support 324
XML Stream-Style Parsers 325
Document Object Model (DOM) 337
LINQ to XML 342
LINQ Helper XML Objects 343
XML Literals 347
Querying XML Documents 349
Reading and Writing XML Documents 351
XSL Transformations 354
XSLT Transforming between XML Standards 357
Other Classes and Interfaces in System.Xml.Xsl 360
XML in ASP.NET 361
The Xml Data Source Server Control 361
The Xml Data Source Control’s Namespace Problem 365
The Xml Server Control 366
Summary 368
CHAPTER 9: ADO.NET AND LINQ 369
ADO.NET Architecture 371
Basic ADO.NET Features 372
Common ADO.NET Tasks 372
Basic ADO.NET Namespaces and Classes 377
ADO.NET Components 378
.NET Data Providers 380
Connection Object 380
Command Object 381
Using Stored Procedures with Command Objects 382
Data Reader Object 385
Executing Commands Asynchronously 387
Data Adapter Objects 389
SQL Server .NET Data Provider 394
OLE DB .NET Data Provider 394
The Data Set Component 395
Data Table Collection 395
Data Relation Collection 395
Extended Properties 396
Creating and Using Data Set Objects 397
ADO.NET Data Table Objects 398
Advanced ADO.NET Features of the Data Set and Data Table Objects 399
Working with the Common Provider Model 401
Connection Pooling in ADO.NET 403
Transactions and System.Transactions 403
Creating Transactions 403
Creating Resource Managers 405
Summary 406
CHAPTER 10: DATA ACCESS WITH THE ENTITY FRAMEWORK 407
Object-Relational Mapping 408
Entity Framework Architecture 408
Conceptual Model 410
Storage Model 416
Mapping Model 417
LINQ to Entities 417
The Object Context 418
Mapping Objects to Entities 419
Simple Mapping 419
Using a Single Table for Multiple Objects 422
Updating the Model 425
Summary 426
CHAPTER 11: SERVICES (XML/WCF) 429
Web Services 430
How This All Fits Together 431
What Makes a WCF Service 431
The Larger Move to SOA 432
Capabilities of WCF 433
Contracts and Metadata 434
Working with the WS-* Protocols 434
Building a WCF Service 436
Creating the Interface 437
Utilizing the Interface 438
Hosting the WCF Service in a Console Application 439
Reviewing the WSDL Document 443
Building a WCF Consumer 445
Adding a Service Reference 445
Reviewing the Reference 447
Configuration File Changes 449
Writing the Consumption Code 451
Working with Data Contracts 453
Namespaces 455
Building the Host 456
Building the Consumer 456
Looking at WSDL and the Schema for
Hello Customer Service 459
Summary 461
PART III: SPECIALIZED TOPICS AND LIBRARIES
CHAPTER 12: XAML ESSENTIALS 465
Features Shared by All XAML Platforms 466
The XAML Markup Language 466
A Sample Page of XAML 467
Code-Behind and Naming of Elements 468
Getting Our Terminology Straight 469
The UIElement and Framework Element Classes 469
Commonly Used Elements 469
Property Setting: Attribute Syntax vs. Element Syntax 470
Referencing Additional Namespaces in XAML 471
The Layout System 472
Measurement Units 472
Panels 472
Sizing and Layout of Elements 479
Controls and Content 484
Content Controls 484
Implications of the Content Model 485
Brushes 486
Resources in XAML 488
The Resources Property 488
More About Resource Dictionaries 489
Scope of a Resource 489
Data Binding 489
Data Binding: Fundamental Concepts 490
The Binding Class and Binding Expressions 491
Data Context 492
Data Bindings between XAML Elements 492
Other Ways to Specify a Data Source 493
Property Change Notifi cation 494
Data Conversion during Binding 494
Dealing with Binding Failures 497
Complex Binding Paths 498
Working with Data Bindings in Code 498
Data Templates and Item Controls 499
Setting the Stage with Some Sample Data 500
Item Controls 501
The XAML List Box 501
Data Templates 503
Data Binding in Data Templates 506
Switching between Data Templates 507
Changing Layout of List Box Items with Items Panel 510
Additional Item Controls 510
Styles 510
What is a Style? 510
Determining the Scope of a Style 511
Implicit Styles 512
Based On Styles 512
Item Container Style 512
Control Templates 513
“Lookless” Controls 513
Reskinning a Check Box 514
Creating Control Templates 515
Summary 515
CHAPTER 13: CREATING XAML APPLICATIONS FOR WINDOWS 8 517
How XAML Diff ers in Windows 8 518
Missing Elements 518
Old Elements Replaced by Functional Equivalents in Windows 8 519
Syntax Diff erences 519
Using Page as the Root Visual Element 520
Windows 8 UI Conventions 520
UI/UX Guidelines 522
Interaction between Your App and the Windows 8 OS 522
Chromeless Apps 522
Snapped Views 522
Typeface and Font Guidelines 523
Sizing and Layout of Visual Elements in an App 523
New Visual Elements in Windows 8 524
App Bar 524
List View, Grid View, and Flip View Controls 527
Pickers 542
Progress Ring 543
Toggle Switch 544
Other New Elements 544
Old Elements with New Usage 545
Changes to the Visual Designer in Visual Studio 2012 547
Better Resource Selector 547
Common vs. Advanced Property Categories 548
Transform Properties 549
Animation 549
Application Templates in Visual Studio 2012 551
Split App 552
Grid App 552
Layout Aware Pages 555
Items in the Common Folder 555
Standard Styles.xaml 555
Online Documentation for Grid App and Split App Templates 556
Implementing a Live Tile 557
Implementing Contracts 558
Summary 560
CHAPTER 14: APPLICATIONS WITH ASP.NET, MVC, JAVASCRIPT, AND HTML 561
Visual Studio Support for ASP.NET 562
Web Site and Web Application Projects 562
Web Server Options 562
Server-Side Development 563
Web Forms 563
Web Pages and Razor 586
ASP.NET MVC 602
Client-Side Web Development 624
Web Development with HTML and Java Script 624
Building Windows 8 Style Apps with HTML and Java Script 638
Summary 644
CHAPTER 15: LOCALIZATION 645
Cultures and Regions 646
Understanding Culture Types 647
Looking at Your Thread 647
Declaring Culture Globally in ASP.NET 649
Adopting Culture Settings in ASP.NET 650
Translating Values and Behaviors 652
Understanding Diff erences in Dates 652
Differences in Numbers and Currencies 654
Understanding Diff erences in Sorting 656
ASP.NET Resource Files 658
Making Use of Local Resources 658
Localization for Windows Store Apps 663
Summary 665
CHAPTER 16: APPLICATION SERVICES 667
Using IIS for Application Services 668
Windows Services 668
Characteristics of a Windows Service 669
Interacting with Windows Services 669
Creating a Windows Service 671
The .NET Framework Classes for Windows Services 671
Other Types of Windows Services 674
Creating a Windows Service in Visual Basic 675
Creating a File Watcher Service 676
Creating a Solution for the Windows Service 677
Adding .NET Components to the Service 677
Installing the Service 680
Starting the Service 681
Uninstalling the Service 682
Communicating with the Service 683
The Service Controller Class 683
Integrating a Service Controller into the Example 685
More about Service Controller 686
Custom Commands 686
Passing Strings to a Service 688
Debugging the Service 689
Summary 690
CHAPTER 17: ASSEMBLIES AND REFLECTION 693
Assemblies 694
The Manifest 694
Assembly Identity 696
Referenced Assemblies 700
Assemblies and Deployment 701
Application-Private Assemblies 701
Shared Assemblies 701
Versioning Issues 703
Application Isolation 703
Side-By-Side Execution 704
Self-Describing Components 704
Version Policies 704
Configuration Files 706
Basics of Refl ection 709
The Assembly Class 710
Getting Currently Loaded Assemblies 711
The Type Class 711
Dynamic Loading of Assemblies 713
The Load From Method of the Assembly Class 713
Dynamic Loading Example 714
Putting Assemblies to Work 716
Summary 716
CHAPTER 18: SECURITY IN THE .NET FRAMEWORK 719
Security Concepts and Defi nitions 720
Windows Store Projects 722
The System.Security.Permissions Namespace 723
Code Access Permissions 727
Identity Permissions 728
Role-Based Permissions 728
Managing Code Access Permission Sets 731
User Access Control 734
Defining Your Application UAC Settings 735
Security Tools 737
Exceptions Using the Security Exception Class 738
Encryption Basics 739
Hash Algorithms 741
Cryptographic Hash Algorithms 741
Symmetric Key Encryption 744
PKCS 747
Secure Sockets Layer 752
Summary 754
CHAPTER 19: PARALLEL PROGRAMMING USING TASKS AND THREADS 757
Launching Parallel Tasks 758
System.Threading.Tasks.Parallel Class 758
Parallel.Invoke 759
Transforming Sequential Code to Parallel Code 764
Detecting Hotspots 765
Measuring Speedups Achieved by Parallel Execution 767
Understanding Parallel 769
Parallelizing Loops 770
Parallel.For 770
Parallel.For Each 775
Exiting from Parallel Loops 781
Specifying the Desired Degree of Parallelism 786
Parallel Options 786
Understanding Hardware Threads and Logical Cores 788
Creating and Managing Tasks 788
System.Threading.Tasks.Task 790
Understanding a Task’s Life Cycle 791
Using Tasks to Parallelize Code 793
Returning Values from Tasks 802
Preparing the Code for Parallelism 805
Understanding Concurrent Collection Features 807
Transforming LINQ into PLINQ 810
Summary 813
CHAPTER 20: DEPLOYING XAML APPLICATIONS VIA THE WINDOWS 8 WINDOWS STORE 815
A New Deployment Option for Windows 8 Apps 815
Deployment of Win RT Apps 816
Developer License 817
Working with the Windows Store 817
Getting an Account at the Windows Store 817
Microsoft Account is Required 818
Windows Store Account Types 818
Steps to Obtain an Account 818
Requirements for Apps in the Windows Store 821
Specific Requirements 822
General Requirements 822
Working with the Windows Store in Visual Studio 2012 823
Options on the Store Menu 824
Creating an App Package 825
Checking to See if an App Meets Requirements 826
Deploying the App to the Windows Store 827
Side-loading for LOB Apps in an Organization 828
Packaging and Validation 829
Preparing Client Machines for Side-loading 829
The Side-loading Operation 830
Summary 831
INDEX 833
关于作者
Bill Sheldon, Visual Basic MVP for 8 years, is the Vice President of Information Technology for Rubio’s Restaurants. He can be found at @Nerd Notes.
Billy Hollis, MVP, is a developer and UX designer at Next Version Systems. He is also a well-known and prolific speaker and trainer.
Rob Windsor, MVP, is Lead Share Point Consultant with Portal Solutions—a Microsoft Gold Partner.
David Mc Carter, MVP, is a principal software engineer/architect and editor-in-chief of dot Net Tips.com.
Gaston C. Hillar, MVP, is tech leader and architect at Bootsoft Inc. He contributes to Dr. Dobbs and blogs for Intel Software Network.
Todd Herman is a senior software engineer at Apx Labs focused on developing a library to support the XMPP standard.