BT

如何利用碎片时间提升技术认知与能力? 点击获取答案

.NET 4 Feature Focus: Type Embedding and Equivalence

| 作者 Jonathan Allen 关注 608 他的粉丝 发布于 2008年11月10日. 估计阅读时间: 6 分钟 | ArchSummit北京2018 共同探讨机器学习、信息安全、微服务治理的关键点

Probably the most common problems with COM Interopt in .NET applications is deployment and versioning. Currently developers have to include "Primary Interopt Assemblies", which in the case of applications like Office be a megabyte or larger. With .NET 4 that will no longer be an issue.

COM Type Embedding allows fragments of interfaces to be compiled into the assemblies that need them. Only the interfaces and methods actually used by the program are included, drastically reducing the overall size of the application.

To keep the VTables accurate, gap commands are included in the assembly's IL as placeholders. These indicate how many method slots are to be skipped. Since COM doesn't allow methods to change location in published interfaces, this will allow support for both forward and backwards versioning.

Another issue this addresses is compiling an application against a newer version, say Word 2007, when the end user may have Word 2003. Checking to see if a method actually exists in the runtime version will have be done in user code, otherwise an access violation will occur. But so long as only backwards compatible methods are used, there should be no other issues.

The use of this will be controlled via a compiler flag. It will default to off for old projects and on for new ones. In the rare event that COM Type Embedding won't work for a given COM interface, a compiler error will occur recommending the flag be turned off.

Two related features are Type Equivalence and Managed Type Embedding. These allows types in different assemblies to be treated as being the same type at runtime. This is crucial for scenarios where multiple libraries are pulling in the same COM interfaces. There are strict rules on this. First of all, all types have to be tagged with a shared GUID so they can be matched up. This isn't an issue with COM, since they are tagged anyways, but it will have to be explicitly applied to managed types.

Regular classes cannot be shared via Type Embedding and Equivalence due to the possibility of differing implementations. Types that can be shared include interfaces, enumerations, delegates, and simple structures.

These features are planned for VB and C#. Developers using C++/CLI normally access COM objects via their header files and Microsoft does not currently plan to offer it for them.

评价本文

专业度
风格

您好,朋友!

您需要 注册一个InfoQ账号 或者 才能进行评论。在您完成注册后还需要进行一些设置。

获得来自InfoQ的更多体验。

告诉我们您的想法

允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p

当有人回复此评论时请E-mail通知我
社区评论

允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p

当有人回复此评论时请E-mail通知我

允许的HTML标签: a,b,br,blockquote,i,li,pre,u,ul,p

当有人回复此评论时请E-mail通知我

讨论

登陆InfoQ,与你最关心的话题互动。


找回密码....

Follow

关注你最喜爱的话题和作者

快速浏览网站内你所感兴趣话题的精选内容。

Like

内容自由定制

选择想要阅读的主题和喜爱的作者定制自己的新闻源。

Notifications

获取更新

设置通知机制以获取内容更新对您而言是否重要

BT