Microsoft 如何创建具有循环引用的程序集? [英] How did Microsoft create assemblies that have circular references?

查看:20
本文介绍了Microsoft 如何创建具有循环引用的程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .NET BCL 中存在以下循环引用:

In the .NET BCL there are circular references between:

  • System.dllSystem.Xml.dll
  • System.dllSystem.Configuration.dll
  • System.Xml.dllSystem.Configuration.dll
  • System.dll and System.Xml.dll
  • System.dll and System.Configuration.dll
  • System.Xml.dll and System.Configuration.dll

这是 .NET Reflector 的屏幕截图,显示了我的意思:

Here's a screenshot from .NET Reflector that shows what I mean:

微软如何创建这些程序集对我来说是个谜.是否需要特殊的编译过程才能允许这样做?我想这里正在发生一些有趣的事情.

How Microsoft created these assemblies is a mystery to me. Is a special compilation process required to allow this? I imagine something interesting is going on here.

推荐答案

我只能说 Mono 项目是如何做到这一点的.这个定理很简单,但代码很混乱.

I can only tell how the Mono Project does this. The theorem is quite simple, though it gives a code mess.

他们首先编译 System.Configuration.dll,不需要引用 System.Xml.dll 的部分.在此之后,他们以正常方式编译 System.Xml.dll.现在魔法来了.他们重新编译 System.configuration.dll,其中需要引用 System.Xml.dll 的部分.现在有了循环引用的成功编译.

They first compile System.Configuration.dll, without the part needing the reference to System.Xml.dll. After this, they compile System.Xml.dll the normal way. Now comes the magic. They recompile System.configuration.dll, with the part needing the reference to System.Xml.dll. Now there's a successful compilation with the circular reference.

简而言之:

  • A 是在没有代码的情况下编译的需要 B 和对 B 的引用.
  • B 已编译.
  • A 被重新编译.

这篇关于Microsoft 如何创建具有循环引用的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆