.NET框架程序设计--NET框架开发平台的体系架构概览(FCL,CTS,CLS)

.NET框架程序设计--NET框架开发平台的体系架构概览(FCL,CTS,CLS)

(一)FCL(.NETFrameworkClassLibrary):.NET框架类库


FCL包含了数以千计的类型,这些类型按照其功能用命名空间(Namespace)来组织。

.NET的各种语言只是定义了一些规则,而我们在实际中的运用,则要在很大程度上去调用FCL中的类型。正是这些类型,使得我们可以运用更少的语言知识,来创建丰富的程序。

CLR和FCL支持我们可以开发以下几种应用程序:

(1)XML Web Services
(2)Web Forms
(3)Windows Forms
(4)Windows CUI(控制台应用程序)
(5)Windows服务(Windows SCM-Service Control Manager-所控制的服务程序)
(6)组件库


(二)CTS(Common Type System)通用类型系统

类型是CLR的基础,Microsoft定义了一个正式规范--CTS来描述类型的定义与行为。

CTS定义了类型以及类型成员的访问控制项。

CTS定义了类型的行为,使得语言与代码行为的分离:我们可以用C++定义自己的类型以及成员,也可以用C#,VB来定义,但是,类型的行为是绝对完全相同的,与语言无关的。


(三)CLS(Common Language Specification)公共语言规范

[参见相应目录例如:\Microsoft Visual Studio .NET 2003\SDK\v1.1\Tool Developers Guide\docs里面的Partition I Architecture.doc]

        要和其他对象完全交互,而不管这些对象是以何种语言实现的,对象必须只向调用方公开那些它们必须与之互用的所有语言的通用功能。为此定义了公共语言规范 (CLS),它是许多应用程序所需的一套基本语言功能。CLS 规则定义了通用类型系统的子集,即所有适用于公共类型系统的规则都适用于 CLS,除非 CLS 中定义了更严格的规则。CLS 通过定义一组开发人员可以确信在多种语言中都可用的功能来增强和确保语言互用性。CLS 还建立了 CLS 遵从性要求,这帮助您确定您的托管代码是否符合 CLS 以及一个给定的工具对托管代码(该代码是使用 CLS 功能的)开发的支持程度。

如果您的组件在对其他代码(包括派生类)公开的 API 中只使用了 CLS 功能,那么可以保证在任何支持 CLS 的编程语言中都可以访问该组件。遵守 CLS 规则、仅使用 CLS 中所包含功能的组件叫做符合 CLS 的组件。

[http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconwritingcls-compliantcode.asp]


如果你想开发一门面向CLR编译器,CLS是必须遵循的。

图中所示:
CLR/CTS提供了一个组特性,一些语言会提供这些特性的一个较大子集(IL提供全部特性)。而CLS是每种语言必须支持的一个最小特性集合。

using System;
//检测CLS兼容性
   //CLR会检测共有类型成员是否符合CLS特性
[assembly:CLSCompliant(true)]
//公有类型,不会报错误
public class App()
{
    
//错误:App.Abc()的返回类型与CLS不兼容
    public UInt32 Abc(){return 0;}
    
//错误:大小写问题引起的CLS不兼容
    public void abc(){}
    
//正确,因为是私有的
    private UInt32 ABC(){return 0;}
}



(四)CTS和CLS都是CLI(Common Language Infrastructure公用语言基础结构)的组成部分。

The basic elements of the CLI are:
·CL:I
·CTS
·CLS
·VES(Virtual Execution System),which executes managed code and lies between the code and the native operating system

And these elements's relation(CLI,CTS,CLS)
:


Each programming language that complies with the CLI uses a subset of the Common Type System that is appropriate for that language. Language-based tools communicate with each other and with the Virtual Execution System using metadata to define and reference the types used to construct the application. When a constructor is called to create an instance of an object, the VES uses the metadata to create instances of types, and to provide data type information to other parts of the infrastructure (remoting services, assembly downloading, security, etc.).
Languages and programming environments that do target the CLI—there are currently more than 20, and the list is growing—produce what is called managed code and managed data. The key to these is metadata—information associated with the code and data that describes the data, identifies the locations of references to objects, and gives the VES enough information to handle most of the overhead associated with older programming models. This overhead includes handling exceptions and security, and providing information to tools that can ensure memory safety. It may also include running on remote systems by creating proxies for the programmer, as well as managing object lifetime (called garbage collection).

Among the things the CLI specifies are the following:

  • The Common Type System

  • The Common Language Specification for publicly available calls

  • Metadata

  • Portable file format for managed code

  • The Common Intermediate Language (CIL) instruction set

  • Basic requirements of a Virtual Execution System

  • A programming framework built on top of all of this

The CLI also bridges the managed and unmanaged worlds. The CLI describes how, in the same program, managed modules can be run with unmanaged modules compiled in native code (machine code, specific to a given system). This interoperation is also crucial to describing how modules can communicate though the VES with the underlying operating systems.

come from 《Common Language Infrastructure Annotated Standard

posted @ 2004-10-19 23:24  cacard  阅读(2257)  评论(1编辑  收藏  举报