Publisher : O'ReillyPub Date : June 2002ISBN : 0-596-00257-2Pages : 574VB.NET Core Classes in a Nutshell, provides a concise and thorough reference to the types found in the core namespa
Trang 1Publisher : O'ReillyPub Date : June 2002ISBN : 0-596-00257-2Pages : 574
VB.NET Core Classes in a Nutshell, provides a concise
and thorough reference to the types found in the core namespaces of the NET Framework Class Library A
companion to VB.NET Language in a Nutshell, this is a
reference that VB.NET programmers will turn to repeatedly Due to a special partnership between O'Reilly and Microsoft, this book also includes a CD that integrates the book's reference into Visual Studio NET.
Trang 2Publisher : O'ReillyPub Date : June 2002ISBN : 0-596-00257-2Pages : 574
Trang 3Chapter 3 Microsoft.Win32
PowerModeChangedEventArgs
PowerModeChangedEventHandler PowerModes
Trang 4Byte
CannotUnloadAppDomainException Char
Trang 5Int64
IntPtr
InvalidCastException
InvalidOperationException InvalidProgramException
IServiceProvider
LoaderOptimization
LoaderOptimizationAttribute LocalDataStoreSlot
NotFiniteNumberException NotImplementedException NotSupportedException
NullReferenceException
Object
ObjectDisposedException ObsoleteAttribute
Trang 6BitArray
CaseInsensitiveComparer
CaseInsensitiveHashCodeProvider CollectionBase
Trang 8PerformanceCounterPermissionEntryCollection PerformanceCounterType
Trang 11ServicePointManager
SocketAddress
SocketPermission
SocketPermissionAttribute TransportType
WebRequest
WebResponse
Chapter 12 System.Net.Sockets AddressFamily
Trang 13TypeDelegator
TypeFilter
Chapter 14 System.Reflection.Emit AssemblyBuilder
Trang 17ThreadAbortException
ThreadExceptionEventArgs ThreadExceptionEventHandler ThreadInterruptedException ThreadPool
ElapsedEventHandler
Timer
TimersDescriptionAttribute
Trang 18XmlReader
XmlResolver
XmlSignificantWhitespace XmlSpace
Trang 19Appendix C Data Marshaling
Appendix D Namespaces and Assemblies Type, Method, Property, Event, and Field Index A
Trang 20I J K L M N O P Q R S T U V W X Y Z
Colophon Index
Trang 21Printed in the United States of America
Published by O'Reilly & Associates, Inc., 1005 Gravenstein HighwayNorth, Sebastopol, CA 95472
O'Reilly & Associates books may be purchased for educational,
business, or sales promotional use Online editions are also available formost titles (http://safari.oreilly.com) For more information contact ourcorporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logoare registered trademarks of O'Reilly & Associates, Inc Many of the
designations used by manufacturers and sellers to distinguish their
products are claimed as trademarks Where those designations appear inthis book, and O'Reilly & Associates, Inc was aware of a trademark
claim, the designations have been printed in caps or initial caps Theassociation between the image of a crawfish and the topic of VB.NETCore Classes is a trademark of O'Reilly & Associates, Inc ActiveX,
IntelliSense, Microsoft, Visual Basic, Visual C++, Visual Studio, Win32,Windows, and Windows NT are registered trademarks, and Visual C# is
a trademark of Microsoft Corporation
While every precaution has been taken in the preparation of this book,the publisher and the author assume no responsibility for errors or
omissions, or for damages resulting from the use of the information
contained herein
Trang 22This book is a desktop reference for the core classes in Microsoft's NETFramework Class Library (FCL) It is intended as a companion volume to
Visual Basic NET Language in a Nutshell, Second Edition, which
provides a reference to the Visual Basic language
Visual Basic NET Core Classes in a Nutshell is divided into two parts.
Part I, which consists of a single chapter, offers a very brief overview ofand introduction to the NET FCL
Part II is a quick reference to the core classes of the FCL 22 of the mostimportant namespaces of the FCL and their more than 700 types,
complete with namespace maps, type descriptions, member signaturesusing VB NET syntax, and useful cross references and annotations Part
II is also available on the CD-ROM that accompanies the book (see
http://examples.oreilly.com/vbdotnetcore/ for the information available onthe CD-ROM)
Trang 23helpful description of each type in the namespaces documented in Part II,along with a useful list of type members that features VB syntax.
Trang 24This book consists of two parts: a single-chapter introduction, and a
reference guide to 22 of the core namespaces of the NET FrameworkClass Library
The single chapter in Part I examines the significance of the NET
Framework Class Library, provides a summary of its contents, discussesthe types found in NET namespaces, and offers some suggestions forexploring the FCL
Part II consists of 22 chapters, each of which is devoted to one of the 22namespaces documented in this book These namespaces provide thecore (or system-level) classes defined in the NET FCL Excluded are thenamespaces whose classes are designed to provide support for
application development The most notable of these excluded
namespaces and their child namespaces are System.Data, System.Web,and System.Windows.Forms
Trang 26Ability to browse the contents of the book in the Visual Studio NETHelp Contents window
Constantly updated Dynamic Help links to relevant Quick Referenceentries as you write Microsoft Visual Basic NET code (these linksappear in a separate Dynamic Help window link group named
Trang 27bookquestions@oreilly.com
If you discover errors in content or encounter any problems in using thisproduct, please report them to:
bookquestions@oreilly.com
For updates and more information, visit:
http://examples.oreilly.com/vbnetcore
Trang 29We have tested and verified the information in this book to the best of ourability, but you may find that features have changed (or even that wehave made mistakes!) Please let us know about any errors you find, aswell as your suggestions for future editions, by writing to:
http://www.oreilly.com/catalog/vbdotnetcorenut
For more information about this book and others, see the O'Reilly websites:
http://www.oreilly.com
http://dotnet.oreilly.com
Trang 30Part II was generated using NET's reflection API Using reflection, wedrilled down into selected classes, structures, enumerations, delegates,and interfaces from the Framework Class Library, and extracted detailedinformation on each type and its members Next, we structured this
information as DocBook XML, which we used to generate the printedpages We also used in-house tools to generate the online Microsoft Help2.0 version that accompanies this book
Trang 31This book would not be possible without the contribution and support ofmany individuals, including family, friends, and the hardworking folks atO'Reilly & Associates, Inc
Brian Jepson and Lenny Muellner of O'Reilly developed the programsresponsible for generating Part II and Glossary Brian also developed thenamespace maps that are found in the overviews that begin each chapter
of the Reference with input from Ted Neward and Peter Drayton TedNeward, Matthew MacDonald, Martin Smith, Steve Spainhour, and BrianJepson wrote the more than 700 namespace and type descriptions thatmake the API reference so valuable
Brad Merrill of Microsoft wrote the sections on regular expressions andprovided content for Appendix A
Brad Abrams and members of his NET Framework team contributed tothe design of the API reference and provided technical review that
dynamic help system He was assisted by Lenny Muellner and Erik Ray.Greg Dickerson and Chris Valdez of the O'Reilly Tech Support grouptested each version of the software Kipper York and Shane McRoberts
of the Microsoft Help team provided invaluable technical assistance atcrucial moments, and Eric Promislow and Vladimir Baikalov of
ActiveState built the install package that plugs our Help collection intoVisual Studio NET Frank Gocinski of the Visual Studio NET IntegrationProgram was instrumental in helping us become full partners in the
program A special tip of the hat to Rob Howard of Microsoft who
supported our original vision and helped us make the right connections to
Trang 32get this project off the ground.
Trang 33This introduction consists of a single chapter that examines thesignificance of the NET Framework Class Library (FCL) and theways it differs from the Win32 API and from COM automation Italso provides an overview of the functionality contained in the FCL
Trang 34The NET Framework is Microsoft's new computing platform that
simplifies the design, development, and deployment of computer
applications Developed particularly to facilitate the creation of Internetapplications and distributed Internet applications, the NET Frameworkfeatures the NET Framework Class Library (FCL), a systematic classframework to be used for the development of system tools and utilities aswell as application software This chapter assesses the significance ofthe NET FCL and discusses accessing it from Visual Basic code
Trang 35Although programmers using languages like C++ have been using
frameworks for system and application development from the very
inception of their language (the Microsoft Foundation Class Library, orMFC, for instance, is a framework for developers of Windows
applications using C++), comprehensive frameworks or class libraries arecomparatively rare in Visual Basic programming For the most part,
programmers of previous versions of Visual Basic depended on two
major sources to extend the Visual Basic language: the Win32 API, andActiveX servers exposed through COM automation
1.1.1 The Win32 API
The Win32 API is a procedural library that allows the developer to createprograms that run under Windows and take advantage of core Windowsoperating system services The Win32 API has been enhanced on aregular basis since it was introduced to support Windows NT 3.0, and itnow consists of several thousand functions and constants located in anumber of dynamic link libraries (DLLs) Because it is a loose collection
of functions, there are'nt necessarily any consistent conventions in
based style of programming using the Win32 API has a number of
Focus on C programmers
Trang 36ByVal hKey As Long, ByVal lpSubKey As String, _
Trang 37Public Declare Function RegQueryValue Lib "advapi32.dll" _ Alias "RegQueryValueA" ( _
ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal lpValue As String, lpcbValue As Long) As LongPrivate Declare Function RegQueryValueEx Lib "advapi32.dll" _ Alias "RegQueryValueExA" ( _
Trang 38
' Get file extension
lPos = InStrRev(1, strFile, ".")
Trang 40If lPos > 0 Then _
Trang 41constants that we intend to use In addition, each registry access requiresthat we do the following:
Trang 42represents a registry key As a result, once the program obtains a
reference to HKEY_CLASSES_ROOT, registry access consists of thefollowing steps:
1 Open the appropriate subkey by calling the top-level key's open method, passing it the path to the subkey to be opened.
Trang 43Dim strFile As String = InputBox("Enter Name of File to Open: ", _ "Open File", "")
Trang 45components
Example 1-3 shows a VB 6 program written using COM automation that,like the programs in Example 1-1 and Example 1-2, launches the
application responsible for handling the data file whose name the userenters in a text box Like the VB.NET program in Example 1-2, it is ashort and fairly simple program that relies on the WScript object availablefrom the Windows Script Host object model
Example 1-3 Launching an application using COM automation
Option Explicit
Trang 47
MsgBox "Open command key not found "
Exit Sub
Trang 48
' Launch application and pass it filename as a parameter lPos = InStr(1, strExe, " %1")
Trang 49programmers were able to work with COM directly For VB
programmers, the Visual Basic environment masked much of thecomplexity of COM The inevitable result was that Visual Basic failed
to give the developer full control over COM when it was needed, andmany Visual Basic programmers often lacked sufficient familiaritywith COM to take advantage even of those features that they wereable to control
In addition, COM did not offer an integrated class library comparable tothe NET FCL Instead, the developers of each application or operatingsystem service were free to implement whatever object model madesense to extend their application As a result, there are major gaps in thefunctionality made available through COM automation, and there is not agood deal of consistency across object models
The NET platform and the NET Framework Class Library were
developed in an effort to address these weaknesses of COM
Trang 50The NET Framework includes the NET Framework Class Library (FCL),
a vast collection of thousands of types (that is, of classes, interfaces,
structures, delegates, and enumerations) that aim at encapsulating thefunctionality of core system and application services in order to makeapplication programming easier and faster There are classes that youcan use to manipulate the file system, access databases, serialize
objects, and launch and synchronize multiple threads of execution, toname just a few
To make working with these classes easy, classes with similar
functionality are grouped together in namespaces Therefore, there is anamespace containing types for drawing, a number of namespaces for.NET remoting, etc In fact, the "intrinsic" functions of the Visual Basic
language (such as InStr, Len, and UBound) are implemented as class
methods in the Microsoft.VisualBasic namespace In total, the NET FCLplaces more than 80 namespaces at your disposal
The NET FCL includes classes with the following functionality:
Data type definition
Some members of the System namespace, such as the Object,String, Int32, and Single classes, form the data types used by VisualBasic NET (as well as by other NET languages that rely on the.NET Common Type System)
Exceptions
When an exception is generated, the CLR provides exception
information to the Exception class (in the System namespace) or toone of the derived classes found throughout the NET FCL
Events and event handlers
The signature of event handlers is represented by the EventHandler
Trang 51Attributes
Attributes allow custom items of information about a program
element to be stored with an assembly's metadata Since this
information becomes a permanent part of the program element'sdescription, it is always available and can be used to modify the
design time, compile time, or runtime behavior of a program element.Attributes are classes derived from the Attribute class (in the Systemnamespace) or one of its derived classes found throughout the NETFCL
Collections and data structures
The NET FCL features a number of general-purpose and more
specialized collection classes The general-purpose classes includethe Array class (in the System namespace) and the ArrayList andCollectionBase classes (in the System.Collection namespace)
Specialized classes include the Stack class, a last-in, first-out
structure, the Queue class, a first-in, first-out structure, in the
System.Collection namespace, and the ListDictionary class, a linkedlist dictionary class, in the System.Collection.Specialized
namespace
Control creation
The NET FCL provides full support for custom Windows and webcontrols that integrate with design-time environments like VisualStudio through a number of classes, including the Container class inthe System.ComponentModel namespace or the CollectionEditorclass in the System.ComponentModel.Design namespace
Configuration settings