图解DotNet框架之一:编译与执行引擎(上)
众所周知,DotNet框架是非常庞大的,光项目创建时的种类就有WPF,WCF,WF这三种最新的技术,还有以前的Web,WinForm,Service,Mobile等等.
这么复杂和庞大的框架,用文字来描述是远远不够的,所以我准备写一系列图文并茂的文章,把我所知道的所有Net框架中的东西全部串联起来,希望可以给大家一个DotNet框架的知识图,本人能力有限,难免有理解错误和表达不清的地方,望大家谅解并指教.
好,我们现在就开始第一张图的学习,再所有的文章写完后,大家将会得到一个完整的框架图。
下面我会做出对这个图的解释,请大家对照图来一步一步的学习。
1.CTS 和 CLS :
CTS:公共类型系统。他是一个集合{类,接口,委托,结构,枚举,类型成员,基本数据类型},只有符合CTS的类型才能在CLR上运行。 简单点说就是VB,C#,C++等DotNet支持的语言的类型集合。这些东西大部分都定义在System.dll中,我们将在下一篇来讨论 system.dll。
CLS:公共语言规范。从图上可以看出,他是CTS的子集,为什么他是子集呢?因为在C#中有Ulong而VB中就没有。看以下代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
在默认.NET开发平台上是不会执行CLS检查的,如果要开启可以在AssemblyInfo.cs中加入代码
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
大家可能要问,为什么要遵循CLS呢?答案在后面给出。
2. CIL,元数据和程序集清单
CIL:公共中间语言。我们大家都知道,在.Net中使用VB写一个DLL,那么在C#的项目中也可以调用,反之亦然。如何实现的呢?就 是CIL了,前面我们说过CLS的作用,并且留下了为什么要遵守CLS的疑问,就是因为.net编译生成的dll或Exe,其实主要是CIL,原数据和程 序集清单这三部分组成。那么要想VB和C#共享,就要有一个通用的规范,它就是CLS了,呵呵,现在明白为什么要CLS了吧,如果你不去遵守CLS也是可 以的,但是就不能保证你的dll的复用性了。
元数据:.net的反射,远程处理,序列化这些东西都很神秘吧,其实他们都是原数据的功劳,你所定义的类,方法,方法的返回类型和参数,属性,字段,都会被编译成元数据,然后当你序列化或反射时,拿这些原数据给你生成一个类。
程序集清单:这个就容易理解了,你添加的dll引用的信息全都在这里。下面是一个Dll中的信息。
原代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
使用.Net自带的 ILDisassembler.exe 察看的IL:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
就是这三样东西组成的dll,让.net实现了远程处理的remoting,反射,序列化和跨平台,跨语言。关于跨平台的问题,我们在下一篇讨论。。