CLR 4.0 有哪些新东西? What's new in CLR 4.0--类型嵌入 Type embedding

简介: 前言 Foreword 自从2005年CLR 2.0发布之后, Microsoft有几年没有更新CLR了. 现在新的版本CLR 4.0即将发布. 本人看了几个英文博文. 综合起来, 摘录其要点. 用一个系列介绍几个CLR4.

前言 Foreword

自从2005年CLR 2.0发布之后, Microsoft有几年没有更新CLR了. 现在新的版本CLR 4.0即将发布. 本人看了几个英文博文. 综合起来, 摘录其要点. 用一个系列介绍几个CLR4.0的新特性. 为照顾英文不好的同学, 特用中英文对照的形式.

Microsoft has not upgraded CLR for years since it released CLR 2.0 in 2005. The new CLR 4.0 is about to release. I read English posts on internet. Do a summary and grab the important points in the English posts. I am going to make a series of posts about what’s new in CLR 4.0. The post is talking about “Type embedding”.

类型嵌入 Type embedding

过去我们用.net开发,部署Office应用时, 我们必须引入Office PIA(Primary interop assembly). 当部署之时, 我们必须在目标机器上安装Office PIA. 虽然Office PIA 体积不大(6M多), 但是这给我们多少带来一些不便.现在CLR4.0的类型嵌入特性给我们提供了一些方便.下面来比较一下: 过去我们开发Office应用, 需要加入Office PIA的引用, 编译后你的Bin目录会有你的程序集和Office PIA的程序集. 当你的应用程序运行之时,你会发现你的应用程序装入了Office PIA的程序集. 在CLR4.0中, 你可以通知CLR将你引用的那些Office PIA的类型嵌入到你的程序集中. 这样在部署之时, Office PIA的程序集就不必一同部署到目标机器上. 具体怎么做呢?

When we develop Office applications using .net in the past, we need to add references to the assemblies of Office PIA. When we deploy the applicaitons, we have to install Office PIA also on the target machines. The size of Office PIA is not so big(about 6M), but it still not convenient enough. Now CLR 4.0 represents us a feature called “Type embedding”. This will provides us conveniency. Let’s work through how we develop Office applications in previous versions of CLR. First step, we need to add reference to Office PIA assemblies, after compiling there are Office PIA assemblies in your bin folder along with your application’s assemblies. If you try to debug your application, you will find your application assembly loads Office PIA assemblies in memory also. In CLR 4.0, you can send a note to CLR that CLR only embeds the types your applicaiton referencing into your assembly. This way you do not need install Office PIA on target machines together with your applicaiton. How to do this?

首先在Visual Studio 2010中加入Office PIA的引用(这和过去一样), 然后在展开引用(References)节点, 找到Office PIA的引用, 在属性(Properties)窗口, 有一个”嵌入互操作类型”(Embed Interop Types), 将其设置成真(True), 再重新编译.

First step you need to add reference to Office PIA assemblies in Visual studio 2010(This is the same as what we did in the past), and then extend the “References” node of your project, click the Office PIA assembly, in “Properties” window, set “Embed interop Types” to True, and compile again.

CLR只将你引用到的类型放入你的程序集中, 同时在你引用到的类型之下, CLR只将你用到的方法和成员以原名称存入你的程序集. 那些未调用的方法将以一个_VtblGap调用来代替, 这些方法的名称将变成以_VtblGap开头的名字.

The CLR rips only the types necessary to complete the calls you have made from your application, and CLR extracts only the methods you have called and replaced all the other methods and Type members with the magic _VblGap calls. Those _VtblGap pseudo methods are emitted in place of unused methods to maintain vtable compatibility.

类型嵌入的限制 Limitations

不能嵌入IL (Can’t embed IL, meaning no classes or static method)

只有元数据能嵌入(接口, 代理, 枚举, 结构) Only metadata is locally embedded (interfaces, delegates, enums, structs )

只有从COM得到的类型才能嵌入. 并且编译器检查这些标签. Only types from Interop Assemblies can be embedded. Compilers check for these attributes

a. [assembly:Guid(…)]

b. [assembly:ImportedFromTypeLib(…)]

参考文献

Ahme的blog  “CLR 4.0: Type Embedding”   http://eknowledger.spaces.live.com/blog/cns!F475D4DE444DB1AB!3238.entry     此博文是英文的, 还配有图片, 英文好的同学可以读读.

mikelij 于 2009.3.8. 23:09

目录
相关文章
|
1月前
|
存储
Google Gemini 对于 CL_ABAP_CONV_IN_CE 类中的 UCCP 方法解释,完全不能看
Google Gemini 对于 CL_ABAP_CONV_IN_CE 类中的 UCCP 方法解释,完全不能看
24 0
|
8月前
|
前端开发
WPF-Binding问题-MVVM中IsChecked属性CommandParameter转换值类型空异常
WPF-Binding问题-MVVM中IsChecked属性CommandParameter转换值类型空异常
86 0
|
10月前
|
开发框架 安全 .NET
【深入理解CLR 五】类型基础
【深入理解CLR 五】类型基础
127 0
|
10月前
|
存储 开发框架 搜索推荐
【深入理解CLR 二】CLR的执行模型(上)
【深入理解CLR 二】CLR的执行模型(上)
110 0
【深入理解CLR 二】CLR的执行模型(上)
|
10月前
|
开发框架 人工智能 自然语言处理
【深入理解CLR 二】CLR的执行模型(下)
【深入理解CLR 二】CLR的执行模型(下)
70 0
|
存储 自然语言处理 BI
SAP ABAP——数据类型(三)【TYPE-POOL和INCLUDE嵌套定义类型】
本文主要介绍一下SAP ABAP中的INCLUDE嵌套定义和类型组TYPE-POOL,类型组讲解主要包括了TYPE-POOL简介,TYPE-POOL的创建和使用以及常用TYPE-POOL的介绍
686 0
SAP ABAP——数据类型(三)【TYPE-POOL和INCLUDE嵌套定义类型】
Action Framework Medium attribute 初始化逻辑
Created by Jerry Wang, last modified on May 05, 2014
109 0
Action Framework Medium attribute 初始化逻辑
|
存储 数据格式 XML
使用带ParserContext参数的Xaml.Load方法
原文:使用带ParserContext参数的Xaml.Load方法 如果一段XAML中存在一个标记需要从外部命名空间中解析, 就需要用到ParserContext类,  具体用法如下: Parser...
740 0