An Overview of the .NET Framework Class Library

< BACK  NEXT >
[oR]

The .NET Framework class library is organized into a hierarchy of namespaces. Each namespace can contain types, such as classes and interfaces, as well as other subordinate namespaces. The root namespace is System, and every .NET Framework application will use some of the types it contains. Yet the types in several other namespaces are also likely to be commonly used by a broad swathe of developers. System is the foundation, but it's by no means the whole story.

The library is a hierarchy of namespaces

How Big Is Big?

If there's any one fact about the .NET Framework class library that you should internalize, it is that the library is big very, very big. Microsoft claims that thousands of people have been working on .NET for several years, and from the looks of it, a large chunk of them were designing and building this class library. The steepest learning curve for most developers adopting the .NET Framework will be learning the .NET Framework class library.

Fortunately, you don't need to learn the whole thing. Unless you have a great deal of free time and remarkably catholic interests, you're unlikely ever to understand every type in the library. Instead, any developer working in the .NET world should first decide which parts of this mountain of software she absolutely needs to understand and then determine which parts she's really interested in. Every developer will need to understand some of its namespaces, but most will be able to ignore many others quite safely.

Providing a large set of generally useful code is clearly a good idea. While the .NET Framework class library probably isn't exactly on the mark in every way in this first release, it does appear to address the right set of problems in a reasonable way. And its straightforward design should make it as approachable as something this big can ever be.

The System Namespace

The System namespace is the ultimate parent of the .NET Framework class library. Along with its large set of subordinate namespaces, System contains many different types. Among the most interesting of these are the following:

  • The core types defined by the CLR's Common Type System, including Int16, Int32, Char, Boolean, and all other standard value types, along with reference types such as Array and Delegate. The fundamental base type Object is also defined here.

  • Console, the class whose WriteLine method was used in the previous chapter to output simple information. This class also provides a corresponding ReadLine method and several others.

  • Math, the class whose Sqrt method was used in the previous chapter to compute the square root of a number. This class has more than two dozen members that provide standard ways to compute a number's sine, cosine, tangent, logarithm, and to perform other common mathematical functions.

  • Environment, a class used to access information about the environment of the currently running application. An application can learn what its current directory is, find out what operating system it's running on, determine how much memory it's using, and more.

  • GC, a class used to affect how and when garbage collection happens. By invoking this class's Collect method, an application can force garbage collection to happen immediately. (This isn't likely to be a good idea, however, since the CLR knows better than you when garbage collection should occur.)

  • Random, a class whose members can be used to compute pseudorandom numbers.

System is the root namespace of the .NET Framework class library

Except for the base CLR types, the types in System sometimes seem to have been placed here because there was no obviously better namespace for them. Still, these types are useful in a broad range of applications.

The types in System are a diverse lot

A Survey of System's Subordinate Namespaces

Directly below System are some two dozen other namespaces, many of which have subnamespaces of their own. Providing even a short survey of these is a daunting task. Nonetheless, before moving on to examine the most important namespaces in some detail, it's important at least to attempt a broad view.

System directly contains more than two dozen namespaces

The Risks and Rewards of a Standard Class Library

The goal of creating a class library is to make life easier for developers. Rather than reinvent wheels from scratch, a developer can reuse existing wheels. Class libraries aren't a new idea, and several useful collections of code exist today. The most popular at the moment is surely the large set of packages defined for the Java environment, which collectively define a set of services that look much like the .NET Framework class library. (In fact, a Java package is very similar to a namespace in the .NET Framework.) The existence of this large set of prepackaged functionality is a major reason for Java's success.

There have been attempts to create broad class libraries that were doomed by their own ambition, however. One of the most visible (and probably most expensive) of these was a project undertaken by the joint Apple/IBM venture Taligent. I once gave a seminar for the technical staff at Taligent, and I don't think I've ever spoken to a more intelligent audience those people were amazing. Yet in part because the class libraries they produced were so complex and had such a long learning curve, they ultimately weren't successful.

Does the .NET Framework class library suffer from this problem? I don't think so. It's certainly big, but a developer doesn't need to understand the whole thing to use just one part of it. Some degree of compartmentalization is critical to a successful class library, since the number of people willing to devote the necessary time to achieve complete mastery is much smaller than those who can benefit from exploiting some parts of it.

Whether what's in the library will meet developer needs remains to be seen. It's early days yet for the .NET Framework, and so we'll surely see some revisions made as this development platform matures. Also, some developers have complained about the lack of source code for the library. Without this, it's difficult to know exactly what's happening inside a class you're inheriting from. Yet the major Java products don't provide source code big software companies are protective of their intellectual property and they're still successful. While source code would be nice, I don't expect its absence to be a major impediment to adoption of the .NET Framework.

Overall, the .NET Framework class library strikes a good balance between power and complexity. While it will certainly require effort to understand, I don't think we're going to see a repeat of the Taligent experience here.

With this lofty goal in mind, this section takes a look at most of the namespaces directly below System, providing a brief description of what each one offers. To give you a visual guide, Table 5-1 shows the primary namespaces in the .NET Framework class library along with their most important children. Note that this chapter does not describe every namespace in this library, and so Table 5-1 is not a complete list.

System.Collections includes types for creating and working with hash tables, arrays, queues, stacks, lists, and other generally useful data structures. These types are defined quite generically. For example, the Stack and Queue classes are defined to contain Objects as their members, which means they can contain values of any CTS type. And like everything in the .NET Framework class library, these types can be used from any CLR-based language. This namespace also contains the subordinate namespace System.Collections.Specialized, which provides types for more narrowly applicable uses, such as a collection of Strings.

System.Collections defines generic types such as stacks and queues

System.ComponentModel contains types for creating various kinds of .NET Framework based components. Among the types it includes is the Component class, which serves as the basis for components used by Windows Forms, described later in this chapter, and for many other classes in the .NET Framework class library. Components, which implement the IComponent interface defined in this namespace, exist inside instances of the Container class, also defined in this namespace. Each Container object implements two more interfaces defined in this namespace: one occurrence of the IContainer interface, along with one ISite interface for each component the container hosts. This namespace also contains types for licensing components. If you're familiar with the COM-based mechanisms for building ActiveX controls, the types defined in this namespace should suggest those commonly used models for building components. System.ComponentModel also contains the subordinate namespace System.ComponentModel.Design, which is full of types that can be used to allow design-time customization of .NET Framework based components.

System.Component-Model provides a foundation for building software components

Table 5-1. The Hierarchy of Major Namespaces in the .NET Framework Class Library
System
Collections
Specialized
ComponentModel
Design
Configuration
Assemblies
Install
Data
OleDb
SqlClient
Diagnostics
DirectoryServices
Drawing
Drawing2D
Imaging
Printing
Text
EnterpriseServices
Globalization
IO
Management
Messaging
Net
Sockets
Reflection
Emit
Resources
Runtime
CompilerServices
InteropServices
Remoting
Serialization
Security
Cryptography
X509Certificates
Xml
Permissions
Policy
Principal
ServiceProcess
Text
RegularExpressions
Threading
Timers
Web
Services
UI
Windows
Forms
Xml
Schema
Serialization
XPath
Xsl

System.Configuration provides types such as the ConfigurationsSettings class that allow accessing configuration information for a .NET Framework based application. It also contains the subordinate namespaces System.Configuration.Assemblies for working with assembly-specific configuration information and System.Configuration.Install for building custom installers for CLR-based software.

System.Configuration supports configuring assemblies and creating installers

System.Data is among the most important namespaces in the .NET Framework class library. The types in this namespace implement ADO.NET, the standard approach to accessing data for .NET Framework applications. Its subordinate namespaces include System.Data.OleDb, which allows access to data sources using OLE DB providers, and System.Data.SqlClient, which allows access to data stored in Microsoft's SQL Server. ADO.NET is described in more detail in Chapter 6.

System.Data contains the types that make up ADO.NET

System.Diagnostics contains a large set of classes, interfaces, structures, and other types that help with debugging .NET Framework applications. For example, the Trace class allows adding to code assertions that verify key conditions, writing messages that trace the flow of execution, and performing other useful functions in released software. The Debug class, also defined in this namespace, provides similar services but is designed to be used during development rather than in a released product.

System.Diagnostics supports tracing, assertions, and more

System.DirectoryServices contains types for accessing Active Directory and other directory services. Prior to .NET, the standard way to expose Windows services was through COM-based interfaces. Active Directory, for instance, can be accessed via the Active Directory Services Interface (ADSI). The .NET Framework largely supersedes COM for new interface definitions, however, and so new ways to expose services must be created using managed code. The types in the System.DirectoryServices namespace are the .NET Framework's analog to ADSI.

System.Directory-Services provides an API to Active Directory

System.Drawing provides a large set of types for using the services of the most recent version of Microsoft's Graphics Device Interface (GDI), known as GDI+. System.Drawing itself includes classes for working with pens, brushes, and other drawing tools, while several subordinate namespaces contain types for related uses. System.Drawing.Drawing2D, for example, contains types for vector graphics and other two-dimensional drawing functions; System.Drawing.Imaging contains types for working with metafiles and other more advanced GDI imaging; System.Drawing.Printing contains types for controlling printers; and System.Drawing.Text contains types for manipulating fonts.

System.Drawing supports creating text and several kinds of graphics

System.EnterpriseServices contains types for accessing the services provided by COM+, including support for distributed transactions, role-based authorization, and object pooling. Unlike most of the functions provided by the .NET Framework class library, the types contained here provide a wrapper around the existing COM+ software rather than reimplementing it as managed code. This important namespace is described in more detail later in this chapter.

System.Enterprise-Services allows access to COM+ services

System.Globalization contains types for creating national calendars, converting to national code pages, formatting dates and times, and other aspects of building software that supports multiple cultures. Globalized software is important, and so many of the .NET Framework's basic functions are automatically culture-aware. For example, conversion to a currency value can automatically examine the caller's culture setting to format the currency appropriately.

System.Globalization helps write software that works in diverse cultures

System.IO provides a large set of types for reading and writing files, directories, and in-memory streams. While access to database management systems is often the main route applications take to data, the ability to work with files is still important. This fundamental namespace is described in more detail later in this chapter.

System.IO supports access to files and directories

System.Management provides types for accessing Windows Management Instrumentation (WMI) data from managed code. WMI is Microsoft's implementation of the Web-Based Enterprise Management (WBEM) initiative supported by many different vendors. A number of the types in this namespace provide support for the WMI Query Language (WQL), a dialect of SQL focused on accessing WMI-related information.

System.Management supports working with WMI data

System.Messaging contains types for accessing Microsoft Message Queuing (MSMQ). MSMQ has several other application programming interfaces (APIs), including a COM-based API and an API defined as a set of C function calls. System.Messaging's types define another API intended for use by managed code.

System.Messaging provides an API for MSMQ

System.Net provides types for accessing several common protocols, including HTTP and the Domain Name System (DNS). It also contains the abstract classes WebRequest and WebResponse, which allow building applications that are unaware of what protocol is being used to communicate. These applications can simply make requests to and get responses from specified URLs and let the underlying software worry about the details. System.Net also contains the subordinate namespace System.Net.Sockets. The types in this namespace provide a managed implementation of the traditional sockets interface to TCP and UDP it's WinSock for the .NET generation. The sockets API, which first appeared in Berkeley UNIX some 20 years ago, refuses to die.

System.Net supports access to HTTP, TCP, and other protocols

System.Reflection contains a large set of types for examining an assembly's metadata. A subordinate namespace, System.Reflection.Emit, contains types that can be used to create other types dynamically. Reflection is described in more detail later in this chapter.

System.Reflection allows access to an assembly's metadata

System.Resources provides types that allow managed code to work effectively with resources. Resources are parts of an application that can be separated from the source code, such as message strings, icons, and bitmaps. A primary use of this namespace's types is to allow an application to display different resources easily when used in different cultures. In other words, the contents of this namespace are especially relevant for internationalized software that must work in many different countries and languages.

System.Resources allows manipulating resources

System.Runtime is a parent namespace that contains several important subordinate namespaces. As its name suggests, System.Runtime.CompilerServices contains types useful for someone writing a compiler for a CLR-based language, and so it is of interest only to a very specialized developer audience. System.Runtime.InteropServices, however, is one of the .NET Framework class library's most important namespaces. It contains types that help in interoperating with non-CLR-based software, such as COM classes, and is described in more detail later in this chapter. System.Runtime.Remoting is another critically important namespace, as the types it contains allow accessing managed objects in other processes and other machines. This technology, known as .NET Remoting, is also described in more detail later in this chapter. Finally, System.Runtime.Serialization contains types for serializing a managed object's state. Serializing a managed object means copying its state (although not its code) into either memory or some more permanent medium such as a file. The ability to work with an object's state in this way is a fundamental feature of the .NET Framework it's used by .NET Remoting, for example so this namespace is also described in more detail later in this chapter.

System.Runtime provides interoperability, remoting, serialization, and other fundamental services

System.Security contains classes, interfaces, enumerations, and subordinate namespaces that provide various security-related functions. The namespace directly contains several fundamental classes, such as the SecurityManager class, which is the primary access point for working with the security system. The subordinate namespace System.Security.Cryptography contains types for using secret and public key cryptography services. Those types can provide access to Windows Cryptographic Service Providers (CSPs) that actually implement algorithms such as DES, RC2, and RSA. System.Security.Cryptography itself also contains two subordinate namespaces. One of them, System.Security.Cryptography.X509Certificates, contains classes for creating and using X.509 version 3 public key certificates for use with Microsoft's Authenticode technology. The other, System.Security.Cryptography.Xml, contains a .NET Framework specific mechanism for digitally signing data described using XML.

System.Security provides cryptography support and other security services

System.Security also contains three other subordinate namespaces. System.Security.Permissions defines types such as a class representing each of the possible permissions for code access security, while System.Security.Policy defines classes such as Site, URL, Publisher, Zone, and others used in defining security policy. How these concepts are used by the CLR was described in Chapter 3's section on code access security. The last of System.Security's three namespace children, System.Security.Principal, contains types for working with security principals. These classes are used by the CLR in implementing the role-based security described in Chapter 3.

System.ServiceProcess contains types for building .NET Framework applications that run as long-lived processes called Windows services. This kind of application was previously known as an NT service and is also sometimes referred to as a demon (often spelled daemon).

System.ServicePro-cess allows creating Windows services

System.Text contains just a small group of classes for working with text. For example, this namespace's UTF8Encoding class can convert Unicode characters from their default encoding into UTF-8 and vice versa. UTF stands for Unicode Transformation Format, and UTF-8 is compatible with the familiar ASCII character representation (although it also allows representing multibyte non-ASCII characters). System.Text also contains the namespace System.Text.RegularExpressions. The types in this namespace allow access to a generic regular expression engine that can be used from any CLR-based language.

System.Text supports text conversion and working with regular expressions

System.Threading is another of the .NET Framework's more important namespaces. The types it contains provide a standard way for developers working in any .NET language to build multithreaded applications. Before .NET, Visual Basic, C++, and other languages all had their own unique approach to threading, with COM's apartments serving as a (complicated) cross-language solution. With the .NET Framework, all CLR-based languages can use the contents of System.Threading to work with threads in a consistent way. Perhaps the most important type in this namespace is the Thread class, which provides methods to start a thread, stop one, cause it to wait for another thread, and more. The namespace also contains classes for using fundamental synchronization constructs, such as mutexes and monitors, and for working with a thread pool.

System.Threading provides standard threading services used by all CLR-based languages

System.Timers contains types for specifying and handling recurring events. The most important class in this namespace is Timer, which allows a developer to specify an interval at which an Elapsed event, defined as part of the Timer class, will be raised in his application. The application can then catch this event and perform some function. For example, an application may wish to check for new mail once every ten minutes. Using this mechanism, the developer could cause the Elapsed event to take place every ten minutes, then put mail-checking code in the handler for this event.

System.Timers supports working with regularly occurring events

System.Web is, after System itself, perhaps the most important namespace in the .NET Framework class library. Comprising many types and many subordinate namespaces, the software it contains implements ASP.NET. The two most important children of System.Web are System.Web.UI, which contains types for building browser-accessible applications, and System.Web.Services, which contains types for creating applications that expose Web services. ASP.NET is described in some detail in Chapter 7.

System.Web implements ASP.NET

System.Windows.Forms contains types used to construct local Windows GUIs. Local GUIs are less important for application developers than they once were a browser interface is now probably more common but they're nonetheless an important topic. Accordingly, this namespace is described in more detail later in this chapter.

System.Win-dows.Forms supports building local Windows GUIs

System.XML contains types useful for working with XML documents. The .NET initiative is shot through with support for XML, and the contents of this namespace provide a great deal of support for developers working with XML-defined data. This namespace is also described in more detail later in this chapter.

System.XML includes a wide range of support for working with XML-defined data

Code provided by a standard library isn't useful unless you know it's there. Accordingly, while memorizing the entire .NET Framework class library isn't necessary, any developer writing CLR-based code should have a broad grasp of what the library makes available. Some namespaces are more important than others, however, and so the remainder of this chapter takes a closer look at some of those that matter most.

Every .NET Framework developer needs a basic knowledge of the class library

< BACK  NEXT >


Understanding. NET. A Tutorial and Analysis
Understanding .NET: A Tutorial and Analysis (Independent Technology Guides)
ISBN: 0201741628
EAN: 2147483647
Year: 2002
Pages: 60

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net