Chapter 1 - The Philosophy of .NET
The content and code of this article is referenced from book Pro C#5.0 and the .NET 4.5 Framework by Apress. The intention of the writing is to review the konwledge and gain better understanding of the .net framework.
1. An Initial look at .net platform
Before Microsoft released the .net platform, software developers who created applications for windows operating system frequently made use of COM (Component object model) programming model, which allowed individuals to build libraires of code can be shared across diverse programming languages.
Benefits of using .net platform.
Interoperability with existing code | Exising COM binaries can commingle with .net, and vice verse |
Support for numerous programming language | .net application can be created using C#, visual basic, F# and so on |
a common runtim engine shared by all .net aware language | |
language intergration | .net supports cross-language inheritance, cross-language exception handling, and cross language debugging of code. |
a comprehensive base class library | The library offers a consistent object model used by all .net languages |
a simplified development model | .net libraries are not registered in system registery. |
2. CLR, CTS and CLS
From a developer's point of view, .net can be understood as a runtime environment and a comprehensive base class library. The runtime layer is properly referred to as the Commong Language Runtim (CLR). The primary role of CLR is to locate, load and manage .net objects on your behalf. Also, CLR takes care of a number of low-level details such as memory management, application hosting, coordinating threads, and performing security checks.
Another building block of the .net paltform is the Commong Type System (CTS), which describes all possible data types and all programming constructs supported by the runtime, specifies how these entities can interact with each other.
However, understand that a given .net-aware language might not support each and every feature defined by the CTS. The Commong Language Specification (CLS) is a related specification that defines a subset of common types and programming constructs that all .net programming languages can agree on.
2.1 Base class libraries
In addition to the CLR, CTS, CLS, .net platform provides a base class library that is available to all .net programming languages. Not only does this base class library encapsulates various primitives such as threads, file I/O, graphical rendering system, but it also provides support for a number of services required by most real-world applications.
3. Assemblies
Regardless of which .net language you choose to program with, understand that despite the fact that .net binaries take the same file extension as unmanaged windows binaries (*.dll or *.exe), they have absolutely no internal similarities. .Net binaries do not contain platform-specific instructions, but rather platform-agnostic Intermediate Language.
3.1 The role of Intermediate Language
CIL is a lauguage that sits above any particular platform-specific instruction set. Because each .net-aware language produces nearly identical CIL instructions, all of them are able to interact within a well-defined binary arena.
The entity that compiles CIL code into meaningful CPU instructions is a JIT compiler, and the .net runtim environment leverages a JIT compiler for different typeos of CPU at runtime.
3.2 The role of metadata
The metadata within the assembly describes each and every type defined in the binary as well as the members of each type. And it is the compiler's job to emit the latest and greatest type metadata.
Metadata is ued by numerous aspects of the .net enviroment. The intelliSense feature provided by tools such as Visual Studio is made possible by reading an assembly's metadata at the design time.
4. Common Language Runtime
The Curx of the CLR is physically represented by a library named mscoree.dll. When an assembly is referenced for use, mscoree.dll is loaded automatically, which in turn loads the required assembly into memory.
5. Namespace
As I mentioned above, the base library in .net pltform provides developers with various of functionalities, and to keep all the types within the base libaries well organiezed, the .net paltform make extensive use of the namespace concept.
A namespace is a grouping of semantically related types contained in an assembly or possibly spread across multiple related assemblies. In addtion, be aware that a single assembly (such as mscorlib.dll) can contain any number of namespaces, each of which can contain any number of types.
System | With System, you find numerous useful types dealing with intrinsic data, mathematical computation, random number, environment variables, and garbage collection. |
System.Collections System.Collections.Generic |
There namespaces define a number of stock container types, as well we types and interfaces that allow you to build customized collections. |
System.Data System.Data.Common System.Data.EntityClient System.Data.SqlClient |
There namespaeces are used for interacting with relactional database using ADO.NET |
System.IO System.IO.Compression System.IO.Ports |
There namespaces are used to work with file I/O, compression data, and port manipulation |
System.Reflection System.Reflection.Emit |
There namespace define types that support runtime type descovery as well as dynamic creation of types |
System.Drawing System.Windows.Forms |
There namespaces define types used to build windows desktop application |
System.Windows System.Windows.Controls System.Windows.Shapes |
WPF |
System.Linq System.xml.Linq System.Data.DataSetExtensions |
LINQ API |
System.Web | ASP.net |
System.ServiceModel | WCF |
System.Workflow.Runtime System.Workflow.Activities |
Windows workflow |
System.Threading System.Threading.Tasks |
|
System.Security | |
System.Xml | |