C# - The CLR and Core Framework

The CLR and Core Framework

System Types

The most fundamental types live directly in the System namespace. These include C#’s built-in types, the Exception base class, the Enum, Array, and Delegate base classes, and Nullable, Type, DateTime, TimeSpan, and Guid. The System namespace also includes types for performing mathematical functions (Math), generating random numbers (Random), and converting between various types (Convert and BitConverter).

the interfaces that define standard protocols used across the .NET Framework for such tasks as formatting (IFormattable) and order comparison (IComparable).

The System namespace also defines the IDisposable interface and the GC class for interacting with the garbage collector.

Text Processing

The System.Text namespace contains the StringBuilder class (the editable or mutable cousin of string), and the types for working with text encodings, such as UTF-8 (Encoding and its subtypes).

The System.Text.RegularExpressions namespace contains types that perform advanced pattern-based search and replace operations;

Collections

The .NET Framework offers a variety of classes for managing collections of items. These include both list- and dictionary-based structures, and work in conjunction with a set of standard interfaces that unify their common characteristics. All collection types are defined in the following namespaces

System.Collections // Nongeneric collections
System.Collections.Generic // Generic collections
System.Collections.Specialized // Strongly typed collections
System.Collections.ObjectModel // Bases for your own collections
System.Collections.Concurrent // Thread-safe collection 

Queries

Language Integrated Query (LINQ) was added in Framework 3.5. LINQ allows you to perform type-safe queries over local and remote collections (e.g., SQL Server tables) and is described in Chapters 8 through 10. A big advantage of LINQ is that it presents a consistent querying API across a variety of domains. The types for resolving LINQ queries reside in these namespaces:

System.Linq // LINQ to Objects and PLINQ
System.Xml.Linq // LINQ to XML
System.Data.Linq // LINQ to SQL
System.Data.Entity // LINQ to Entities (Entity Framework)
System.Linq.Expressions // For building expressions manually

The LINQ to SQL and Entity Framework APIs leverage lower-level ADO.NET types in the System.Data namespace.

XML

XML is used widely within the .NET Framework, and so is supported extensively. Chapter focuses entirely on LINQ to XML—a lightweight XML document object model that can be constructed and queried through LINQ. describes the older W3C DOM, as well as the performant low-level reader/writer classes and the Framework’s support for XML schemas, stylesheets, and XPath. The XML namespaces are:

System.Xml // XmlReader, XmlWriter + the old W3C DOM
System.Xml.Linq // The LINQ to XML DOM
System.Xml.Schema // Support for XSD
System.Xml.XPath // XPath query language
System.Xml.Xsl // Stylesheet support
System.Xml.Serialization // Declarative XML serialization for .NET types

Diagnostics and Code Contracts

we cover .NET’s logging and assertion facilities and the new code contracts system in Framework 4.0. We also describe how to interact with other processes, write to the Windows event log, and use performance counters for monitoring. The types for this are defined in and under System.Diagnostics.

Streams and I/O

The Framework provides a stream-based model for low-level input/output. Streams are typically used to read and write directly to files and network connections, and can be chained or wrapped in decorator streams to add compression or encryption functionality. we describes .NET’s stream architecture, as well as the specific support for working with files and directories, compression, isolated storage, pipes, and memory-mapped files. The Stream and I/O types are defined in and under the System.IO namespace.

Networking

You can directly access standard network protocols such as HTTP, FTP, TCP/IP, and SMTP via the types in System.Net. we demonstrate how to communicate using each of these protocols, starting with simple tasks such as downloading from a web page, and finishing with using TCP/IP directly to retrieve POP3 email. Here are the namespaces we cover:

System.Net
System.Net.Mail // For sending mail via SMTP
System.Net.Sockets // TCP, UDP, and IP

Serialization

The Framework provides several systems for saving and restoring objects to a binary or text representation. Such systems are required for distributed application technologies, such as WCF, Web Services, and Remoting, and also to save and restore objects to a file. we cover all three serialization engines: the data contract serializer, the binary serializer, and the XML serializer. The types for serialization reside in the following namespaces:

System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Binary
System.Runtime.Serialization.Formatters.SOAP
System.Xml.Serialization

Assemblies, Reflection, and Attributes

The assemblies into which C# programs compile comprise executable instructions (stored as intermediate language or IL) and metadata, which describes the program’s types, members, and attributes. Through reflection, you can inspect this metadata at runtime, and do such things as dynamically invoke methods. With Reflection.Emit, you can construct new code on the fly.

reflection and attributes—describing how to inspect metadata, dynamically invoke functions, write custom attributes, emit new types, and parse raw IL. The types for using reflection and working with assemblies reside in the following namespaces:

System
System.Reflection
System.Reflection.Emit

Security

The .NET Framework provides its own security layer, allowing you to both sandbox other assemblies and be sandboxed yourself. we cover code access, role, and identity security, and the new transparency model in CLR 4.0. We then describe cryptography in the Framework, covering encryption, hashing, and data protection. The types for this are defined in:

System.Security
System.Security.Permissions
System.Security.Policy
System.Security.Cryptography

Threading and Parallel Programming

Multithreading allows you to execute code in parallel

All types for threading are in and under the System.Threading namespace.

Applied Technologies

User Interface Technologies

The .NET Framework provides four APIs for user-interface-based applications:
ASP.NET (System.Web.UI)
For writing thin client applications that run over a standard web browser
Silverlight
For providing a rich user interface inside a web browser
Windows Presentation Foundation (System.Windows)
For writing rich client applications
Windows Forms (System.Windows.Forms)
For maintaining legacy rich client applications

Backend Technologies

ADO.NET

Windows Workflow

Windows Workflow is not strictly a backend technology—you can use it anywhere (an example is page flow, in the UI).

Workflow came originally with .NET Framework 3.0, with its types defined in the System.WorkFlow namespace. Workflow has been substantially revised in Framework 4.0; the new types live in and under the System.Activities namespace.

COM+ and MSMQ

The Framework allows you to interoperate with COM+ for services such as distributed transactions, via types in the System.EnterpriseServices namespace. It also supports MSMQ (Microsoft Message Queuing) for asynchronous, one-way messaging through types in System.Messaging.

Distributed System Technologies

Windows Communication Foundation (WCF)

Remoting and Web Services

The types for Remoting are in or under System.Runtime.Remoting; the types for Web Services are under System.Web.Services.

CardSpace

CardSpace is a token-based authentication and identity management protocol designed to simplify password management for end users. The technology has received little attention because of the difficulty in porting tokens across machines (OpenID is a popular alternative that avoids this problem).

WCF allows you to specify a CardSpace identity when connecting through a secure HTTP channel, through types in the System.IdentityModel.Claims and System.Iden tityModel.Policy namespaces